0

Whenever i attempt to use the WaitForChild event, it doesnt work and i have zero clue why

local ui = game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui

script.Parent.Touched:Connect(function()
    wait()
    ui.Enabled = true
    
end)

script.Parent.TouchEnded:Connect(function()
    wait()
    ui.Enabled = false
end)

The errors goes like so: Workspace.Part.ShopOpen:1: attempt to index nil with 'WaitForChild'

ben
  • 1
  • 2

1 Answers1

1

The WaitForChild isn't returning nil, it is the LocalPlayer that is returning nil. I'm guessing since it's returning nil that you accidentally put it in a Server Script. If that is the case you can only access LocalPlayer through Local Scripts. By the way if you change it to a Local Script the script.Parent.Touched wont work as Local Scripts don't run in workspace, so you would have to put it somewhere like StarterCharacter scripts and instead of script.Parent.Touched, you use game.Workspace.Part.Touched.

qurxts
  • 11
  • 1