Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't this debounce work properly?



local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local t = char.Torso



local deb = false

function onActivated()
	if deb then
		
		return
	
	end	
	
	print("Tool Activated!")
	
	deb = true

	local ball = Instance.new("Part")
		ball.FormFactor = "Custom"
		ball.Shape = "Ball"
		ball.BottomSurface = "Smooth"
		ball.TopSurface = "Smooth"
		ball.CanCollide = false
		ball.Size = Vector3.new(0.5,0.5,0.5)
		ball.BrickColor = BrickColor.new("Really black")



	local subject = Instance.new("Part")
		subject.Parent = t
		subject.FormFactor = "Custom"
		subject.CanCollide = false
		subject.Size = Vector3.new(0.1,0.1,0.1)
		subject.BrickColor = BrickColor.new("Really black")
		ball.Parent = subject

	local w = Instance.new("ManualWeld")
		w.Name = "Weldy"
		w.Parent = subject
		w.Part0 = t
		w.Part1 = subject

		w.C0 = CFrame.new(0,0,0)


	local w2 = Instance.new("ManualWeld")
		w2.Name = "Weldy"
		w2.Parent = ball
		w2.Part0 = subject
		w2.Part1 = ball

		w2.C0 = CFrame.new(0,0,2.5)




local angle = 0

	while true do
		w.C0 = CFrame.new(0,0,0) * CFrame.Angles(0, angle, 0)
		wait()
		angle = angle + 0.1
	end
	wait(5)
	deb = false
end


script.Parent.Activated:connect(onActivated)

Okay, I'll explain the problem im having.

You left click, a ball starts rotating around your torso. Everything fine. Debounce works fine 100% but:

If you left click, the ball appears rotating, the debounce countdowns to 0. and in that countdown iterval you start spamming left click. It jumps out the debounce and starts spamming and ignoring the debounce. Any help ?

2 comments

1

Is this the full script? There are a few things that shouldn't work, but, you say it works

0

It is the full script.

1 answer

I believe line 11 needs to be if deb==true thenbut it's very hard to tell... In the future you should properly indent your code as it will help you and other spot errors and make corrections.

3 comments

0

No, line 11 will return True if deb is True and return False if deb is false. I do agree though, the style is atrocious.

0

Apart from my code being atrocious in style which is my own problem, I want to find a fix to this debounce which is doing weird. Any help ?

0

Mars, for real? It's a shortcut, a faster cleaner way to code!

This discussion is preserved as it was. New answers, comments, and votes are closed.