Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unable To Define PlayerScripts?

Asked by 5 years ago

Here is my code:

01script.Parent.Touched:Connect(function(hit)
02    if script.Parent.Working.Value == false then
03        if hit.Parent:FindFirstChild("Humanoid")then
04            script.Parent.Working.Value = true
05            local player = hit.Parent
06            local Player = game.Players:FindFirstChild(player.Name)
07            local Humanoid = player.Humanoid
08            local PlayerScripts = Player:FindFirstChild("PlayerScripts")
09            local PlayerModule = PlayerScripts:FindFirstChild("PlayerModule")
10            local Controls = PlayerModule:GetControls()
11            Controls:Disable()
12            Humanoid:MoveTo(script.Parent.Parent.TargetPoint.Position)
13 
14            wait(3)
15            script.Parent.Working.Value = false
16            Controls:Enable()
17 
18        end
19    end
20end)

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

Log in to vote
0
Answered by 5 years ago

Instead of using FindFirstChild, consider using WaitForChild

Ad

Answer this question