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 nil with 'WaitForChild'?

so i am trying to make an aot game so im making a tips and tricks menu where if you stand next to a character a gui will show and if you press a button it will show some tips and tricks. but i got an error saying attempt to index nil with 'WaitForChild' it is a normal script that is enabling the playergui if that helps

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		game.Players.LocalPlayer:WaitForChild("PlayerGui").Tips.Enabled = true
	end
end)

1 answer

✓ Accepted answer

You can't use game.Players.LocalPlayer because your script are a Script (ServerScript).

Use the service Players to find the player that touch the part with :GetPlayerFromCharacter()

script.Parent.Touched:Connect(function(hit)
	local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if Player then
		Player:WaitForChild('PlayerGui'):WaitForChild('Tips').Enabled = true
	end
end)

2 comments

0

thank you it worked

0

You shouldn't drop the Humanoid filter.

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