I was using ProximityPrompts to change a frames visibility. It didn't work even though I tried both types of scripts (local and server). While using a server script I got the error
"Workspace.JuicePart.ProximityPrompt.Script:2: attempt to index nil with 'WaitForChild' "
and the local script gave no errors but still didn't work. I also tried using FindFirstChild and that also didn't work.
Code:
1 | local player = game.Players.LocalPlayer |
2 | local DrinksFrame = player:WaitForChild( "PlayerGui" ).ShopUi.Drinks |
3 |
4 | game.Workspace.JuicePart.ProximityPrompt.Triggered:Connect( function () --wait until the ProximityPrompt is triggered |
5 | print ( "Juice shop opened" ) |
6 | wait() |
7 | DrinksFrame.Visible = true -- try to set the visibility to true |
8 | end ) |
I dont think you can use waitforchild on playergui. Not sure tho but try removing the waitforchild
I solved my own question a lot earlier just posting the answer if anyone in the future wants this!
(Nature fresh is a model btw)
1 | local JuicePart = game.Workspace:WaitForChild( "NatureFresh" ).JuicePart.ProximityPrompt |
2 | local DrinksFrame = player:WaitForChild( "PlayerGui" ).ShopUi.Drinks |
3 |
4 | JuicePart.Triggered:Connect( function () |
5 | print ( "Shop opened" ) |
6 | DrinksFrame.Visible = true |
7 | wait() |
8 | end ) |
its in a local script and JuicePart is a proximity prompt.
All I changed was I added a variable for the proximity prompt. I think what it was doing before was running this code before the part existed.