Cant get script that changes to a random text when pressed to function fully

I am trying to make a script that will change the text of a surface gui to something random when ever a player collides with it. But it only changes once, and wont change again after another press. Here is the code


debounce = false

local Quotes = {"Test 1","Test2","Test3","Test4"}
script.Parent.Touched:connect(function(hit)
	if not debounce then
		debounce = true
		if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
		script.Parent.SurfaceGui.Frame.TextLabel.Text = Quotes[math.random(1, #Quotes)]
	end
end
end)

Once debounce is set to true in your code, it can’t run again. The fix is to set it to false later since that’s what a debounce is for.

1 Like
local debounce = false

local Quotes = {"Test 1","Test2","Test3","Test4"}
script.Parent.Touched:connect(function(hit)
	if not debounce then
		debounce = true
		if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
		script.Parent.SurfaceGui.Frame.TextLabel.Text = Quotes[math.random(1, #Quotes)]
        task.wait(0.5)
        debounce = false
	end
end
end)

the code i would use

1 Like

Oh! Okay thanks so much, now I know what debounce does. I just put it in there because it would not run properly without it. Thanks so much!

Thank you! Very helpful of you.

1 Like

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