Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

howdo i make debounce to that?

Asked by 3 years ago
Edited 3 years ago
local players = game:GetService("Players")

function touched(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1) --The size it will grow once touched
    end
end

script.Parent.Touched:Connect(touched)

i would be happy if you could explain where the debounce should be and how to add it

1 answer

Log in to vote
0
Answered by 3 years ago

Hopefully, this explains it

The if statement can't run unless the debounce is set to false and when it's set to false it sets it to true so you can only run it once every 1-second example you can change this in line 4 hopefully, that explained it you can read more about it here if my explanation was a bit bad :D https://developer.roblox.com/en-us/articles/Debounce

local players = game:GetService("Players")

local Debounce = false
local CoolDown = 1 -- your cooldown on the debounce in seconds

function touched(otherPart)

    if Debounce == false then -- so if the debounce is set to false then we set it to true meaning that the if statement cant run without the debounce being false if that makes sense
        Debounce = true

        local partParent = otherPart.Parent
        local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")

        if humanoid then
            script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1) --The size it will grow once touched
        end
        wait(CoolDown)
    end
end

script.Parent.Touched:Connect(touched)
0
now it wont grow like before but thanks for trying :) thedukke1 9 — 3y
0
it should work but your code is the problem if you want to add debounce you would have to do it differently but you have the basics of the debounce with the if statements johnoscarbhv1 137 — 3y
Ad

Answer this question