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

attempt to index local 'player' (a nil value)?

Why doesn't this script work, I even checked if the thing that touches has a humanoid, and even with adding that - I get the same error I had. But why? Why do I even get an error without touching the flag? Here is the script:

script.Parent.Touched:Connect(function(hit) 

local  humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local  player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if player.Team.Name == "Wave" and humanoid.Parent:FindFirstChild("Invincibility") == false then
script.Parent.Parent = humanoid.Parent
local head = humanoid.Parent.Head
script.Parent.CFrame = head.CFrame * CFrame.new(0,2,0)
local weld = Instance.new("Weld")
weld.Part0 = head
weld.C0 = head.CFrame:inverse()
weld.Part1 = script.Parent
weld.C1 = script.Parent.CFrame:inverse()
weld.Parent = script.Parent
script.Parent.Anchored = false

end
end
end)


func =  script.Parent.RemoveWeld
	
	function func.OnInvoke()
		print(1)
	end
	

Why doesn't it work, and why do I get an error without touching the brick??

2 comments

0

Try using print as the debug tool.

0

"Nil Value" means the script doesn't knows what is the value. Meaning the script doesn't knows what the value "Player" is. I am not really good at scripting but try defining player in a different way, I guess.

1 answer

✓ Accepted answer

Your problem is that you automatically assume that every humanoid has a player attached to it. That is wrong. You need to check if game.Players:GetPlayerFromCharacter(part.Parent) then local player =game.Players:GetPlayerFromCharacter(part.Parent) end Hope that helps. If it doesn't, I'll run some tests once I get home and take a closer look at it.

1 comment

0

Hey, I found out about the issue before, but thanks for answering! No need to test out at home :)

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