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

in which way can i add this script a debounce?

Asked by 6 years ago
local Spirit = script.Parent
 Spirit.Touched:connect(function(entity) 
    if entity.Parent.Name == "FireEssence" and game.Players:FindFirstChild(entity.Parent.Parent.Name)then
        local debounce = true
        local Man =  entity.Parent.Parent.Parent
        local RealMan = game.Players:FindFirstChild(entity.Parent.Parent.Name)
        local Bro = RealMan:FindFirstChild("leaderstats")
        local EXP = Bro:FindFirstChild("EXP")
        EXP.Value = EXP.Value + 10
        print(EXP.Value)
        script.Parent.Transparency = 0.5
        script.Parent.CanCollide = false
        wait(20) 
        script.Parent.Transparency = 0
        script.Parent.CanCollide = true              
    end

 end)

Help please.

SuVee, Aspiring Developer.

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

RBXScriptSignal:connect() with a lowercase C is deprecated, prefer RBXScriptSignal:Connect().

To get the player, you should use game.Players:GetPlayerFromCharacter().

Here's how a debounce would work:

local IsDebounced = false

script.Parent.Touched:Connect(function(TouchedPart)
    if IsDebounced then
        return
    end

    IsDebounce = true
    print("Hi!")
    wait(10)
    IsDebounce = false
end)

There is no point using Instance:FindFirstChild() in your code if you are not going to check whether or not it returned nil.

Ad

Answer this question