Can anyone tell me why output gives the error attempt to index a nil value(in the script for when it's fired)? The purpose of the script is to change someone to a team color and respawn them when they have a certain amount of deaths, but it isn't working.
Code to fire it(in a LocalScript, in StarterPack):
-- Variables
local Player = game.Players.LocalPlayer
local Stats = Player:WaitForChild("leaderstats")
if Stats["Deaths"].Value == 3 then
game.ReplicatedStorage.RemoteEvent:FireServer(game.Players.LocalPlayer)
end
script:Destroy()
Code for when it's fired(in a ServerScript, in ServerScriptService.(this is the one that is erroring)):
game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(Player)
game.Players:FindFirstChild(Player).TeamColor = game.Teams.TestTeam.TeamColor
game.Players:FindFirstChild(Player):LoadCharacter()
end)
Any help appreciated.
