Proximity prompt making event fire multiple times

hi, i have this prompt that brings up a gui, you can close it and reactive it with the prompt:

but as you can see, everytime you use the prompt to reopen the gui, it stars firing twice, and then three times and so on

this is the script, nothing much:

local prompt = script.Parent

prompt.Triggered:Connect(function(player)
	local frame = player.PlayerGui.ScreenGui.Frame
	
	prompt.Enabled = false
	frame.Visible = true
	
	
	frame.print.MouseButton1Click:Connect(function()
		print("ok")
	end)
	
	
	frame.close.MouseButton1Click:Connect(function()
		frame.Visible = false
		script.Parent.Enabled = true
	end)
	
	
end)

any way to fix this?

Why don’t you just add these 2 functions in a LocalScript inside the frame itself, instead of the proximity prompt script. This should prevent the problem altogether.

2 Likes

the actual script im making does need to be server sided

It shouldn’t matter if there is already a local script inside the frame. Which I’m guessing is the case because you reference the PlayerGui.

i have another script that im making that needs to be server sided, i just made a simpler script because the problem already appears here in this simpler one

if there is no solution to this i could make it client sided, im just wondering if there is one as that would be better

You need to disconnect the button events after the player closes it:

local prompt = script.Parent

prompt.Triggered:Connect(function(player)
	local frame = player.PlayerGui.ScreenGui.Frame
	
	prompt.Enabled = false
	frame.Visible = true
	
	
	local printConn = frame.print.MouseButton1Click:Connect(function() -- set up for disconnection
		print("ok")
	end)
	
	
	frame.close.MouseButton1Click:Once(function() -- only connects once, it disconnects automatically after 1 time
		frame.Visible = false
		script.Parent.Enabled = true
printConn:Disconnect() --disconnects and stops button from running until prompt is triggered again
	end)
	
	
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.