wait(1) local debounce = false function Own(hit) if debounce == false then local player = hit.Parent:FindFirstChild("Humanoid") if player then local owner = Instance.new('StringValue', script.Parent) local debounce = true wait(2) local debounce = false end end end script.Parent.Head.Touched:connect(Own)
Nevermind, I fixed it, this is the working script.
The problem with the first one was, after it was touched, alot of String Values would show up instead of 1.
wait(1) local debounce = false function Own(hit) if not debounce then debounce = true local player = hit.Parent:FindFirstChild("Humanoid") if player then local owner = Instance.new('StringValue', script.Parent) wait(2) local debounce = false else return end end end script.Parent.Head.Touched:connect(Own)
Edit: I see that you've fixed your code, but you still may want to take a look at this. Using wait()/"blocking delays" isn't usually desirable in code.
Instead of using a true/false variable and wait(), try recording the last time the function was run (using time()), finding the difference between that time and the current time when the function is called, and then comparing that to a delay value. If the difference between the last time the function ran and the current time is greater than a debounce time, then run the function again and set the last ran time to the current one.
Hint:
if(time() - lastTimeRun > debounceTimeConstant) lastTimeRun = time() end
If you have any further questions, feel free to ask!