Hello Devs!
I’m trying to make treadmill but I have problem with cooldown. When Someone spam “E” then value is adding to queue and when he click “E” to normal train then he gots a multiplied value like
Normally:
Wait 3 seconds to get one speed
Spam:
Spams 10 times and later click “E” to train normally the value:
Wait 3 seconds to get 10 speed
Server Script:
RemotesFolder.Train.OnServerEvent:Connect(function(plr)
local char = plr.Character
local hum = char.Humanoid
local animator = hum.Animator
local anim = script.Animation
local track = animator:LoadAnimation(anim)
for i, v in pairs(workspace.Bierznie:GetChildren()) do
if (plr.Character.Head.Position - v.Hitbox.Position).Magnitude < 5 then
if plr.Values.Req.Value <= plr.leaderstats.Energy.Value then
if plr.Values.Training.Value == false then
plr.Values.Training.Value = true
print("Training")
plr.Character.Humanoid.WalkSpeed = 0
plr.Character.Head.CFrame = v.Teleport.CFrame
plr.Character.Humanoid.JumpHeight = 0
track:Play()
track:AdjustSpeed(1.5)
wait(2)
plr.Values.Training.Value = plr.Values.Training.Value
repeat
wait(3)
if plr.leaderstats.Energy.Value < plr.Values.Req.Value or plr.Values.Training.Value == false then
break
end
plr.leaderstats.Speed.Value += 1
plr.leaderstats.Energy.Value -= plr.Values.Req.Value
plr.Values.Req.Value = plr.Values.Req.Value + 4.5
until plr.leaderstats.Energy.Value < plr.Values.Req.Value or plr.Values.Training.Value == false
track:Stop()
plr.Values.Training.Value = false
plr.Character.Humanoid.WalkSpeed = 16
plr.Character.Humanoid.JumpHeight = 7.2
else
track:Stop()
plr.Values.Training.Value = false
plr.Character.Humanoid.WalkSpeed = 16
plr.Character.Humanoid.JumpHeight = 7.2
end
end
end
end
end)
local script:
--// Services
local plrs = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local RepStor = game:GetService("ReplicatedStorage")
--// Variables
local plr = plrs.LocalPlayer
local RemotesFolder = RepStor.Remotes
local TrainEvent = RemotesFolder.Train
--// Functions
--[[Train]]--
UIS.InputEnded:Connect(function(input, busy)
if not busy then
if input.KeyCode == Enum.KeyCode.E then
TrainEvent:FireServer()
end
end
end)