want to make a script that check player team every second.
But bad error lives in 11 line. Why cant this order work?
–ServerScriptService.score:11: attempt to index nil with ‘TeamColor’
(script is on serverscriptservice, and not localscript.)
want to make a script that check player team every second.
But bad error lives in 11 line. Why cant this order work?
–ServerScriptService.score:11: attempt to index nil with ‘TeamColor’
(script is on serverscriptservice, and not localscript.)
You can’t get localplayer from a serverscript.
you cannot use local player on a server side script, try using the player added function
What player added function means?
something like this -
game.Players.PlayerAdded:Connect(function(player)
if player.TeamColor == BrickColor.new("Really black") then
-- do something
end
end
like it?
I used this to give damage to particular team before, but not worked(exactly, It worked at studio but not worked in game…)
So I didnt use playeradded function.
If you okay, can you check this script? I will tell you what the particular values mean
Why not just loop through the players instead?
while true do
for _, guhil in ipairs(game.Players:GetPlayers()) do
if guhil.TeamColor == BrickColor.new("Really black") then
-- reset of code here
end
end
game:GetService("RunService").Heartbeat:Wait() -- replacement for wait()
end
game.Players.PlayerAdded:Connect(function(player)
while wait(1) do
if player.TeamColor == BrickColor.new("Pearl") then
print("Player is on team")
end
end
end)
Try this.
Also I recommend using player.Team.Name instead.
WHY IT WORKING???
I tried playeradded function before but it didnt work that time!
huhuh I still dont know what was the problem. but okay the problem is now gone lol!
“game.Players.LocalPlayer” is only defined in local scripts, avoid using it in server scripts.
local players = game:GetService("Players")
task.spawn(function()
while task.wait() do
for _, player in pairs(players:GetPlayers()) do
if player.TeamColor = BrickColor.new("Really black") then
--do code
end
end
end
end)
Just use task.wait()
, it’s exactly the same but it takes less time to write.
Use task.wait()
instead of wait()
, it’s newer, and better.
Oh, okay. I haven’t seen task.wait since I have programmed in a while, thank you for telling me.