How do I make this script work "better"

What I’m trying to do is, well, Have a UI frame be opened with a ProximityPrompt, Now the script works but it is super slow for some reason. It works the first time its used but after that it for some reason forces you to hold the proximityprompt button multiple times until it will open again. When multiple people are trying to open the same thing it causes a bunch of problems to occur like it becoming even slower.

I’ve already tried to fix it on my own, but it either has the same outcome, or it only works once. The script is a normal script inside of a ProximityPrompt, and that is just inside a part.

t

local prompt = script.Parent
local open = false
prompt.Triggered:Connect(function(player)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local ScreenGui = PlayerGui.ScreenGui
	local Frame = ScreenGui.StoreFrame
	if open == false then
		open = true
		Frame.Visible = true
	else
		open = false
		Frame.Visible = false
	end
end)
1 Like

Do it in a local script instead of server script.

you cant use prompts on a local script, many faulty errs.

does it run multiple times? print something

Yes you can? If not, then I guess all the times I’ve used them in local scripts were just my imagination, right?

It only runs once, and it also doesn’t show any errors

I dont know if it runs better but this is more simplier try this

local prompt = script.Parent
prompt.Triggered:Connect(function(player)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local ScreenGui = PlayerGui.ScreenGui
	local Frame = ScreenGui.StoreFrame
	Frame.Visible = not Frame.Visible
end)

It doesn’t run better but at least its easier to understand I guess

ok ive got this for you
btw put this inside the screengui

local gui = script.Parent
local prompt = -- your prompt location
prompt.Tiggered:Connect(function()
Gui.StoreFrame.Visible = not Gui.StoreFrame.Visible
end)