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

My animation only plays once what can be the problem?

Asked by 4 years ago

https://gyazo.com/2d72010dd31b46ae69f101513bfb643f

Heres local script

local Player = game:GetService("Players")
local rp = game:GetService("ReplicatedStorage")
local Lancer = rp:WaitForChild("Lancer")

local UIS = game:GetService("UserInputService")

local debounce = false
local cooldown = 1

UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then
    return

    elseif input.KeyCode == Enum.KeyCode.E and debounce == false then
    debounce = true

    Lancer:FireServer()



end
end)

Lancer.OnClientEvent:Connect(function()

    wait(cooldown)
    debounce = false
end)

And normal script

local rp = game:GetService("ReplicatedStorage")

local Lancer = rp:WaitForChild("Lancer")

local Animation = game.Workspace.Animations:WaitForChild("Swing")

    Lancer.OnServerEvent:Connect(function(Player) 

          local Character = Player.Character 

         local Humanoid = Character:FindFirstChild("Humanoid")

            local LoadedAnimation = Humanoid:LoadAnimation(Animation)

        LoadedAnimation:Play() 

end)

2 answers

Log in to vote
1
Answered by
oilkas 364 Moderation Voter
4 years ago

To reset the debounce, edit this in your server script:

local rp = game:GetService("ReplicatedStorage")
local Lancer = rp:WaitForChild("Lancer")
local Animation = AnimationFolderHere:WaitForChild("AnimationNameHere") -- Find the animation

Lancer.OnServerEvent:Connect(function(Player) -- Listen to event fire
    local Character = Player.Character -- Get the player's character
    local Humanoid = Character:FindFirstChild("Humanoid")
    local LoadedAnimation = Humanoid:LoadAnimation(Animation) -- Load the animation
    LoadedAnimation:Play() -- Play the animation
    Lancer:FireClient(Player)
end)
Ad
Log in to vote
1
Answered by 4 years ago

You are not firing the client once the animation has played, so the debounce never resets to false. Make sure to reset your debounce or else it will only work once.

0
dude im dumb can u tel me how to put it in the script :) themaxogamer 58 — 4y
0
I'd recommend reading up about it so you learn first hand. Good luck! https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events adrrob1002 5 — 4y

Answer this question