I am working on a local script that detects the team a player is on and changes their team if they die.
while true do
local t1 = game.Teams:WaitForChild("T1")
local t2 = game.Teams.T2
local t3 = game.Teams.T3
local t4 = game.Teams.T4
local tu = game.Teams.Undescided
local player = game.Players.LocalPlayer
local plr = player.Character.Humanoid
plr.Died:Connect(function()
if player.Team == t1 or player.Team == t2 or player.Team == t3 or player.Team == t4 then
player.Team = tu
end
end)
wait(.5)
end
The error is on line 8 saying " ReplicatedFirst.DeathScript:8: attempt to index field 'Character' (a nil value)" I'm pretty sure that I've used the LocalPlayer.Character before in a local script, but for some reason this one isn't working correctly. I'm sure this is something that I have set up wrong but I would love some help getting it to work. (This is a local script in the ReplicatedFirst folder) Let me know if you need any more information! Thank you!

1 comment
I recommend not putting the code into a loop, as it'll keep on repeatedly setting up the same event over-and-over again.