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

Player walkspeed resets to normal when i click?

Asked by
CDXKIE 130
3 years ago

So ive made a hammer that does a lot of damage to a humanoid, and then i made a script that slows down the player when you equip the hammer.

local Tool = script.Parent
local plr = game:GetService('Players').LocalPlayer
local Enabled = false

Tool.Activated:Connect(function()
    if not Enabled then
        Enabled = true
        plr.Character.Humanoid.WalkSpeed = 3
    else
        Enabled = false
        plr.Character.Humanoid.WalkSpeed = 16
    end
end)

But then whenever i clicked the walkspeed resets to normal! I thought it might be the damage script so i put that in server storage to see if it worked after that, and even without the damage scripts the walkspeed resets to normal when you click the mouse! It also turns it back to 3 when you click again. Could anyone point out a problem as this is completely beyond me lol.

1 answer

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
3 years ago
Edited 3 years ago

That's because the script just toggles the walkspeed when walking.


local Tool = script.Parent local plr = game:GetService('Players').LocalPlayer local deb = false local cooldown = 0.5 -- how long you walk slower in seconds you can set it to anything you want for example 1 to 1 second Tool.Activated:Connect(function() -- fires on activated if deb then return end -- stop when debounce is active deb = true plr.Character.Humanoid.WalkSpeed = 3 wait(cooldown) plr.Character.Humanoid.WalkSpeed = 16 deb = false end)
1
Thanks! CDXKIE 130 — 3y
Ad

Answer this question