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

made an animation that will infinitely loop despite it only meant to play once. Any Ideas as to why?

I am in the midddle of making a game, I recently added a kick move and animation, which works fine, but now for some reason if I punch, the Punch animation will loop forever and I have no idea why, any ideas as to why this happening? Im new to scripting sorry

I am just running it using Studio

Clientside Script

local UserInputService = game:GetService("UserInputService")
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Humanoid = Char.Humanoid

local Hit = script:WaitForChild("Hit")

local Re = game:GetService("ReplicatedStorage").Punch
local Punch = game:GetService("ReplicatedStorage").PunchAnim

local Debounce = true
local Cooldown = 2
local Key = 'E'

UserInputService.InputBegan:Connect(function(input, Istyping)
	if Istyping then return end
	if input.KeyCode == Enum.KeyCode[Key] and Debounce and Char then
		Debounce = false
		
		local Load = Humanoid:LoadAnimation(Punch)
		Load:Play()
		
		if Load.IsPlaying and not Hit.Value then
			Re:FireServer()
		end
		
		wait(Cooldown)
		Debounce = true
	end
end)

Server Script

local Combat = game:GetService("ReplicatedStorage").Punch
local plr = game.Players.LocalPlayer

Combat.OnServerEvent:Connect(function(plr)
	local Char = plr.Character or plr.CharacterAdded:Wait()
	if not Char.Punch.Hit.Value then
		Char.Punch.Hit.Value = true
		local A = true
		Char.LeftHand.Touched:Connect(function(h)
			if A and h.Parent.Name ~= plr.Name and h.Parent:FindFirstChild("Humanoid") then
				A = false
				local E = h.Parent.Humanoid
				E:TakeDamage(4)
				wait(3)
				A = true
				Char.Punch.Hit.Value = false
			end
		end)
	end
end)

I think I might have missed something obvious I can also post the Kick scripts if you want/need them.

1 comment

0

When you have export your animation the loop was be coched

1 answer

✓ Accepted answer
UserInputService.InputBegan:Connect(function(input, Istyping)
    if input.KeyCode == Enum.KeyCode[Key] and Debounce and Char and not Istyping then
        Debounce = false

        local Load = Humanoid:LoadAnimation(Punch)
	Load.Looped = false -- Test with that.
        Load:Play()

        if Load.IsPlaying and not Hit.Value then
            Re:FireServer()
        end

        wait(Cooldown)
        Debounce = true
    end
end)

4 comments

0

I tried this, the animation doesn't play at all

0

Oh wait, sorry, my internet was messing up, thank you, this worked perfectly.

0

can i copy dis script :)

0

pls accept answer after you get your problem solved. it helps everyone see it was solved.

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