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.
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)
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)