Cooldown able to be bypassed

I’m trying to make it so that when you click the button it changes your walkspeed which works, but the cooldown is able to be bypassed and glitched

local button = script.Parent:WaitForChild("lol")
local textlabal = script.Parent:WaitForChild("lol2")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local debounce = true

local randomnum = 100


button.Activated:Connect(function(a)
	
if a then
		
		if debounce then
			
			humanoid.WalkSpeed = Random.new():NextNumber(0,randomnum)
		textlabal.Text = "Walkspeed: "..math.floor(humanoid.WalkSpeed)
		textlabal.TextColor3 = Color3.fromRGB(255, 0, 0)
		
		end
					
		
		debounce = false
		
		task.wait(5)
		
		
		if not debounce then
			debounce = true	
			textlabal.TextColor3 = Color3.fromRGB(255, 255, 255)
		end
	

		
	
end
end)

I’m an absolute beginner at scripting so if i do smth stupid that’s on me

after activating the button, you should check if debounce is set to false.

button.Activated:Connect(function(a))
if not debounce then return end

also i just want to show the way i would have made the script since you are a beginner.

local button = script.Parent:WaitForChild("lol")
local textlabal = script.Parent:WaitForChild("lol2")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local canClickButton = true --> i would name it just to make things easier

button.MouseButton1Click:Connect(function()
     if canClickButton == false then return end --> now you dont have to check if canClick is true

     canClickButton = false

     humanoid.WalkSpeed = math.random(0, 100) --> this is much simpler than the random.new() stuff but you only get integers
     textlabal.Text = "Walkspeed: "..humanoid.WalkSpeed
     textlabal.TextColor3 = Color3.fromRGB(255,0,0)

     task.wait(5)

     canClickButton = true
     textlabal.TextColor3 = Color3.fromRGB(255, 255, 255)


end

i get so annoyed when scripts look unorganised so if you want to just go to the script tab and click format document

by the way what is “a”?

2 Likes

yup, this did it, thanks :head_shaking_vertically:

btw “a” is when its activated but a variable. idk

1 Like

thanks once again!

i literally don’t know any easier way to get around anything so mb

i also don’t know how you guys’ name stuff sometimes and make it “easier” but i guess ill find out eventually

like do people have the same idea but just different names when their name stuff. i don’t get it

i also did the format thing thanks

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