Playing Animations Locally

i am making a simple lobby and I need to clone the local player on the client side, then play an idle animation. When I try to play the animation, they dont play. Everything is unanchored. When I clone the player on the server and insert a similar script, it works. What is the problem?

Can you tell me this information please:

1.- It is a script or a local script,
2.- Where it is located.
3.- The script code.

1 Like

its obviously a localscript
its in startercharacterscripts

local events = game.ReplicatedStorage:WaitForChild("Events")
local cp = events:WaitForChild("CreatePlayer")

function createcharater(char, basenum)
	repeat wait() until char:FindFirstChild("Animate")
	local dupe = char:Clone()

	dupe.Parent = workspace
	dupe:SetPrimaryPartCFrame(workspace["Base" .. basenum].Pad.CFrame)
	dupe:MoveTo(workspace["Base" .. basenum].Pad.Position)
	
	for _, item in pairs(dupe:GetChildren()) do
		if item:IsA("Script") or item:IsA("LocalScript") then
			item:Destroy()
		end
	end
	
	spawn(function() idle(char) end)
end


function idle(char)
	local Humanoid = char:WaitForChild("Humanoid")

	while true do
		local idle = Humanoid:WaitForChild("Animator"):LoadAnimation(script.Animations["Idle" .. math.random(1,3)])
		idle:Play()
		idle.Stopped:Wait()
	end
end

cp.OnClientEvent:Connect(function(basenum)
	createcharater(script.Parent, basenum)
end)

Edit: I think it may be clogging up on the load animation part???
Edit2: I added prints to see where it failed. It is “playing” the animation but it is not detecting the stop.

1 Like

Try to put after the local dupe line this:

dupe.Archivable = true
1 Like

I got the error:

local events = game.ReplicatedStorage:WaitForChild("Events")
local cp = events:WaitForChild("CreatePlayer")

function createcharater(char, basenum)
	char:WaitForChild("Animate")
	char.Archivable = true
	local dupe = char:Clone()
	
	dupe.Parent = workspace
	dupe.PrimaryPart.Anchored = true
	dupe.PrimaryPart.CFrame = workspace["Base" .. basenum].Pad.CFrame

	for _, item in pairs(dupe:GetChildren()) do
		if item:IsA("Script") or item:IsA("LocalScript") then
			item:Destroy()
		end
	end

    --Here you was putting the original char instead of the cloned
	idle(dupe)
end


function idle(char)
	local Humanoid = char:WaitForChild("Humanoid")
	
	local idle = Humanoid.Animator:LoadAnimation(script.Animations["Idle" .. math.random(1,3)])
	idle.Looped = true
	idle.Priority = Enum.AnimationPriority.Action
	idle:Play()
end

cp.OnClientEvent:Connect(function(basenum)
	createcharater(script.Parent, basenum)
end)

That was done on the server side. @ancadejo10 What error???

1 Like

You were putting in the “idle function” first parameter the playerCharacter instead of the cloned.

2 Likes

Thanks so much! I didn’t see that mistake! (LOL)

1 Like