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

[SOLVED] ProximityPrompt won't set a frame's visibility to true?

Asked by 3 years ago
Edited 3 years ago

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:

local player = game.Players.LocalPlayer
local DrinksFrame = player:WaitForChild("PlayerGui").ShopUi.Drinks

game.Workspace.JuicePart.ProximityPrompt.Triggered:Connect(function() --wait until the ProximityPrompt is triggered 
    print("Juice shop opened")
    wait()
    DrinksFrame.Visible = true -- try to set the visibility to true
end) 

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I dont think you can use waitforchild on playergui. Not sure tho but try removing the waitforchild

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)

local JuicePart = game.Workspace:WaitForChild("NatureFresh").JuicePart.ProximityPrompt
local DrinksFrame = player:WaitForChild("PlayerGui").ShopUi.Drinks

JuicePart.Triggered:Connect(function()
    print("Shop opened")
    DrinksFrame.Visible = true
    wait()
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.

Answer this question