#Team check script error

11 messages · Page 1 of 1 (latest)

digital kraken
#

while wait(10) do

if player.Team.Name == "Police officer" then
    for i,player in ipairs(game.Players:GetPlayers()) do
        player.leaderstats["money"].Value += 100
    end
end

end

It's a short script, but it doesn't work... 😦
How to fix this script?

spring mirage
#

The script worked fine for me. Is it in a LocalScript or Script?

#

And if possible could you send the whole script?

digital kraken
#

The script is inside the ServerScriptService, and that's all it's about

spring mirage
#

How are you getting the player? And are you getting any errors?

digital kraken
#

game:GetService("Players")

while wait(10) do

if player.Team.Name == "Police officer" then
    for i,player in ipairs(game.Players:GetPlayers()) do
        player.leaderstats["money"].Value += 100
    end
end

end

I add game:GetService("Players")

Output:
ServerScriptService.givemoney:5: attempt to index nil with 'Team' - server - givemoney:5

little mossBOT
#

studio** You are now Level 2! **studio

spring mirage
#

Ah yeah you gotta loop through all the players first. Then check if the player is in the right team

#

For loop before the if statement

warm path
#
local Teams = game:GetService("Teams")

local PoliceTeam = Teams:FindFirstChild("Police officer")

while task.wait(10)
    for _, Player in PoliceTeam:GetPlayers() do
        Player.leaderstats["money"].Value += 100
    end
end
warm path