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

Why is the debounce cool down not working?

Asked by
Prestory 1395 Moderation Voter
6 years ago
local rmtevent = game:GetService('ReplicatedStorage'):WaitForChild('Plotting')
local player = game.Players.LocalPlayer
local Tool = script.Parent;
enabled = true


function onActivated()
    if not enabled  then
        return
    end
enabled = false
rmtevent.OnServerEvent:Connect(function(plr)             
local value = math.random(1,script.Parent.Handle.Value.Value) 
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + value 

    wait(.8)

end)


    enabled = true
end


function onEquipped()
print("Equipped")
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

The debounce in this code is not working the cool down why is it not working please help thanks.

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You're trying to set the the callback for rmtevent.OnServerEvent on the client (a localscript).

When the tool is Activated, you need to call RemoteEvent:FireServer() with what arguments are necessary.

You'll have to split your code between the server and client, like so:

A LocalScript (in the tool)

local remoteevent = game:GetService("ReplicatedStorage"):WaitForChild("Plotting");
local player = game.Players.LocalPlayer;
local tool = script.Parent;

tool.Activated:connect(function()
    if(not enabled)then
        return;
    else
        enabled = false;
        remoteevent:FireServer(tool.Handle.Value.Value);
        wait(0.8);
        enabled = true;
    end
end)

tool.Equipped:connect(function()
    print("Equipped");
end

A Script in ServerScriptService

local remoteevent = game:GetService("ReplicatedStorage"):WaitForChild("Plotting");

remoteevent.OnServerEvent:connect(function(player, value)
    local strength = math.random(1, value);
    player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + strength;
end)
0
Thanks alot again bruh your always helpful Prestory 1395 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Sometimes it doesn't work if you wait until end. Try doing a simple print so it sees it as it's actually waiting for something

local rmtevent = game:GetService('ReplicatedStorage'):WaitForChild('Plotting')
local player = game.Players.LocalPlayer
local Tool = script.Parent;
enabled = true


function onActivated()
    if not enabled  then
        return
    end
enabled = false
rmtevent.OnServerEvent:Connect(function(plr)             
local value = math.random(1,script.Parent.Handle.Value.Value) 
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + value 

    wait(.8)
print("Done")

end)


    enabled = true
end


function onEquipped()
print("Equipped")
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)


Answer this question