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

Debounce in remote event not working?

Asked by 4 years ago
Edited 4 years ago

Help me I am trying to fire a remote event when the owner of the tycoon hits the gamepass buttton however when i touched it, it keeps on firing even I added a debounce.

local id = script.Parent.Parent.Gamepass.Value
local Owner = script.Parent.Parent.Parent.Parent.Owner
local RM1 = game.ReplicatedStorage.RemoteEvents.GamepassPurchaseButton
script.Parent.Touched:Connect(function(hit)
    local debounce = false
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if script.Parent.CanCollide == true then
            if player ~= nil then
                if Owner.Value == player then
                    if hit.Parent:FindFirstChild("Humanoid") then
                        if hit.Parent.Humanoid.Health > 0 then
                        if not debounce then
                            RM1:FireClient(player)
                            wait(10)
                            debounce = false
                        end
                    end
                end
            end
        end
    end     
end)

2 answers

Log in to vote
0
Answered by 4 years ago

It's simply because you aren't setting the debounce to true!

On line 15, I think you meant to say debounce = true;, not debounce = false;.

Hope this helps! If this works, mark it!

0
Did not notice it thank you gamingwithjbthepro 76 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

This block of code:

if not debounce then
    RM1:FireClient(player)
    wait(10)
    debounce = false
end

Needs a set debounce. So, do it like this:

if not debounce and debounce == false then
    debounce = true
    RM1:FireClient(player)
    wait(10)
    debounce = false
end

You didn't set the debounce to true before anything else. Hope this works!

Answer this question