I wanted to make a script in which after you keep shovelling , using a tool, Your walkspeed will increase.
And after 6 seconds after you stop shovelling, your walkspeed will go back to normal.
What have i done:
I tried to make it so it waits after it increases the speed, then puts it back to normal.
But i found out that the function keeps on running even when its called again. Therefore the walkspeed goes back to normal even when im still shoveling.
First a function is called in a local script inside the starter pack.
showel = script.Parent
showelFunc= game.ReplicatedStorage.Shovelled
event = game.ReplicatedStorage.Snow
SnowBallName = "SnowPatchSCRIPTED"
local Debounce = true
showel.Equipped:Connect(function()
local plr = game.Players.LocalPlayer
local plrgui = game.Players.LocalPlayer.PlayerGui
Txt = plrgui:WaitForChild("Popout").PopoutFrame.Amount
local Character = plr.Character
local Humanoid = Character:FindFirstChild("Humanoid")
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
if Debounce then
if mouse.Target.Name == SnowBallName and (mouse.Target.Position - showel.Handle.Position).Magnitude < 15 then
event:FireServer(x, mouse.Target)
end
end
end)
end)
The above script basically fires an event which increases the snowballs value.(Which is in leaderstats)
Then, a local script detects when the snowballs value is increased
plr = game.Players.LocalPlayer
Func = game.ReplicatedStorage.Shovelled
ldb = plr:WaitForChild("leaderstats")
Deb = true
snowballs = ldb:FindFirstChild("SnowBalls")
snowballs:GetPropertyChangedSignal("Value"):Connect(function()
print("b")
Deb = false
local snb = snowballs.Value
local B = 0.1
local x = B + snb
local character = plr.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = x
wait(10)
local character = plr.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.WalkSpeed = 16
end)
But as said above, it makes the speed normal even when the player is shovelling.
I would appretiate help.