I wanted help on how to make a skill with cooldown on server side and client side animation, I already tried to do it by bool inside the player but it gives a bug that if you press 2x the animation runs 2x and it gets weird, does anyone have any tips on how I do this ?
Can you show us some of your code?
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Hrp = Char:WaitForChild("HumanoidRootPart")
local Hum = Char:WaitForChild("Humanoid")
local StartAnimation = Hum:LoadAnimation(script:WaitForChild("Spin"))
local Tween = game:GetService("TweenService")
local Event = game.ReplicatedStorage:WaitForChild("LeviSpin1")
local ContextActionService = game:GetService("ContextActionService")
local Mouse = Player:GetMouse()
local Mobile = false
if (UIS.TouchEnabled) then
Mobile = true
else
Mobile = false
end
local function Attack()
if not Player:FindFirstChild("Skill1CD") then
Event:FireServer()
StartAnimation:Play()
task.delay(.3,function()
local bodyVelocity = Instance.new("BodyVelocity") game.Debris:AddItem(bodyVelocity,1)
bodyVelocity.MaxForce = Vector3.new(100000, 0, 100000)
if Mobile then
bodyVelocity.Velocity = Hrp.CFrame.LookVector * 100
else
Hrp.CFrame = CFrame.lookAt(Hrp.Position, Mouse.Hit.Position)
bodyVelocity.Velocity = ((Mouse.Hit.Position - Hrp.Position).Unit * 75) * Vector3.new(1, 0, 1)
end
bodyVelocity.Parent = Hrp
end)
end
end
ContextActionService:BindAction("Attack1", Attack, true, Enum.KeyCode.One)
ContextActionService:SetPosition("Attack1", UDim2.new(1, -70, 0, 10))
ContextActionService:SetTitle("Attack1","Skill 1")
this is a local code for a dash skill, but like i said if i click twice the animation doubles , If you have any tips or ideas I would be very grateful.
Okay so the reason your animation is playing twice is because it’s restarting everytime you press the key “One”
So you should add a check to see if it’s playing already or not like this
If not StartAnimation.IsPlaying then
StartAnimation:Play()
end
this helps with the animation issue, but there is still the problem of the local dash that sometimes doubles due to server and client delays, would you know any method to make a more efficient debounce?
Try this
It’s for a debounce
I see, I was having doubts about the client not syncing with the server but I realized that this will not happen because the client will not fire so it will be on cooldown longer than the server itself, now everything makes sense. Thanks man, you helped me a lot. I wish you the best!