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

How to Add Debounce in This StealBall Script?

I have more GIFs to show lol. I tried to add in a debounce, but it never worked the way I wanted to.

Script:

local tool = script.Parent
local handle = tool:WaitForChild("Handle")

print("Loaded")

handle.Touched:connect(function(hit)
    if hit.Parent ~= nil then  -- if what you hit still exists
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
        if player and player.Character then 
            local char = player.Character
            local torso = char:findFirstChild("Torso")
            local hum = char:findFirstChild("Humanoid")
            if torso and hum and hum.Health > 0 then -- make sure they aren't dead
                local dist = (torso.Position - handle.Position).magnitude
                if dist < 5 then 
                    tool.Parent = char
                end
            end   
        end
    end   
end)

Script Above GIF

GIF #1

How I Want It to Work

GIF #2

Thanks,

LukeGabrieI aka EnergyBrickz

1 comment

0

First, I don't see where your debounce is, I also have a question on where this script is place and what script is it and how did you get GIF #2 if it never worked the way you wanted it to?

1 answer

✓ Accepted answer

This is fairly simple, I just put the debounce as the first thing in my code

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local debounce = false

print("Loaded")

handle.Touched:connect(function(hit)
	if not debounce then
		debounce = true
		   if hit.Parent ~= nil then  -- if what you hit still exists
			local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
			if player and player.Character then 
				local char = player.Character
				local torso = char:findFirstChild("Torso")
				local hum = char:findFirstChild("Humanoid")
				if torso and hum and hum.Health > 0 then -- make sure they aren't dead
				    local dist = (torso.Position - handle.Position).magnitude
				    if dist < 5 then 
				        tool.Parent = char
				    end
				end   
			end
		end 
	end
	wait(1) --Put the wait amount for the use of this to however much you'd like
	debounce = false
end)

Hope this helped!

1 comment

0

It still doesnt work lol, I'm still getting the ball pretty quick

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