Every time I trigger a Proximity Prompt, the function is repeating several times. Does anyone know, how I can do, if a player triggered a Proximity Prompt, the function will only work one time?
add a debounce some like
local a = false
if not a then
a = true
a = false
end
Do you know, how I can do, that every single player has her/his own debounce?
I’m guessing you may need to disconnect a function
are you handling it on the server ?
You have to disconnect the function outside the function
As in it’s executing multiple times or not executing?
Edit: I misread the code mb. Disconnect the function after everything that should be triggered has been triggered.
srry, I do not really understand what do you mean
I got this now?
The issue is that the connection is supposed to end when all of the necessary code has been executed. When you assign a function, the block of code will be ignored and disconnected before it can be triggered in this case
Check if the function has been fully executed and disconnect once it’s done.
local finished = false
if condition then
finished = true
end
while finished == false do --don't execute the following code until finished
wait(0.1)
end
triggered:Disconnect()
This should work but it’s not ideal. Create your own verification to check if the code has been fully executed
make a table, as triggered returns the player set the players debounce in the table
example:
local global_debounces = {}
prompt.Triggered:Connect(function(p)
if global_debounces[p] then return end
global_debounces[p] = true
task.wait(--[[change how you like]])
global_debounces[p] = nil --I am setting it to nil as I dont want to store a useless "false" value
end)
Won’t this cause a memory leak
how? please explain. This would not cause a memory leak as the entry of the table called “p” is removed with nil when the debounce ends, when there is no debounces the global_debounces will be same as a empty table.
there is a reason why I said “useless false value”
I’m assuming OP has put this function within another function, hence the multiple executions
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.