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

Unable To Define PlayerScripts?

Here is my code:

script.Parent.Touched:Connect(function(hit)
	if script.Parent.Working.Value == false then
		if hit.Parent:FindFirstChild("Humanoid")then
			script.Parent.Working.Value = true
			local player = hit.Parent
			local Player = game.Players:FindFirstChild(player.Name)
			local Humanoid = player.Humanoid
			local PlayerScripts = Player:FindFirstChild("PlayerScripts")
			local PlayerModule = PlayerScripts:FindFirstChild("PlayerModule")
			local Controls = PlayerModule:GetControls()
			Controls:Disable()
			Humanoid:MoveTo(script.Parent.Parent.TargetPoint.Position)
			
			wait(3)
			script.Parent.Working.Value = false
			Controls:Enable()

		end
	end
end)

Currently when I touch the part, it gives me the error: ** 10:00:08.135 - Workspace.Detector.TouchPart.Script:9: attempt to index local 'PlayerScripts' (a nil value) 10:00:08.136 - Stack Begin 10:00:08.136 - Script 'Workspace.Detector.TouchPart.Script', Line 9 10:00:08.136 - Stack End **

If you know why I cannot define the PlayerScripts, please help. Thank you!

1 answer

Instead of using FindFirstChild, consider using WaitForChild

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