Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"attempt to index local 'Player' (a nil value)" How to fix this error?

game.Workspace.CaseD.Touched:connect(function(User)
wait(.5)
if User.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(User.Parent)
if Player.TeamColor == "Bright bluish green" and KF.Value == false then
KF.Value = true
script.Parent.ServerEffects.Flag:Clone().Parent = User.Parent.Head
end
end
end)

14:04:35.247 - Workspace.ServerScripts.MasterScript:42: attempt to index local 'Player' (a nil value) 14:04:35.248 - Stack Begin 14:04:35.249 - Script 'Workspace.ServerScripts.MasterScript', Line 42 14:04:35.249 - Stack End

1 answer

check isnt Player nil. TeamColor is a brickcolor, not string.

game.Workspace.CaseD.Touched:connect(function(User)
wait(.5)
if User.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(User.Parent)
if Player ~= nil then
if Player.TeamColor == BrickColor.new("Bright bluish green") and KF.Value == false then
KF.Value = true
script.Parent.ServerEffects.Flag:Clone().Parent = User.Parent.Head
end
end
end
end)

EDIT: Try now

3 comments

0

But now if the player has the right team and the value is false he doesnt get the effect.

1

TeamColor is a BrickColor value, not a string

0

Oh yeah. Didnt see it :/

This discussion is preserved as it was. New answers, comments, and votes are closed.