Animation problem


I can not understand animations and how they work, I need to do that when I hold down the mouse button, the first animation is activated, and then when I pressed down, the second animation is activated. And also that the first animation would stop at the last moment and the humanoid was in a sitting position.

localscript:


local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()


UIS.InputBegan:Connect(function(inp, gp)
	if gp then return end
	if inp.UserInputType == Enum.UserInputType.MouseButton1 then
		RS.Attack:FireServer("Arg1")
		local particle = RS.Particle.Part.Attachment:Clone()
		particle.Parent = char.Torso
	UIS.InputEnded:Connect(function(inp, gm)
		if gm then return end
			if inp.UserInputType == Enum.UserInputType.MouseButton1 then
				print("End")
				RS.Attack:FireServer("Arg2")
				particle:Destroy()
			end
		end)
		
	end
end)

script

local RS = game:GetService("ReplicatedStorage")

local Animation = RS:WaitForChild("Animation")
local Animo1 = Animation:WaitForChild("Animo1")
local Animo2 = Animation:WaitForChild("Animo2")

RS:WaitForChild("Attack").OnServerEvent:Connect(function(plr, arg)
	local char = plr.Character
	local humanoid = char:WaitForChild("Humanoid")
	local Animoo1 = humanoid:LoadAnimation(Animo1)
	local Animoo2 = humanoid:LoadAnimation(Animo2)

	if arg == "Arg1" then
		Animoo1:Play()
	elseif arg == "Arg2" then
		Animoo2:Play()
	end
end)

2 Likes

You should be playing animations on the client, since it is more performant and they will automatically replicate (for character animations).

Don’t load a new animation every time you want to play it. Load both animations at the top of your local script (be sure this script is in StarterCharacterScripts and not StarterPlayerScripts so it will be run with each new character and humanoid), and then play those preloaded tracks directly.

1 Like

Thank you, but do you know how you could fix the animation of the humanoid in the sitting position (when you press the mouse button, the animation will stop at the point where he is sitting)?