Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My animation only plays once what can be the problem?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.