Can't Figure Out This Animation Set Up

I have been having trouble trying to figure out how to animate my custom characters, I have come so close except there are two problems with this, on the local side the player will not stop playing their animation, the second problem is the scripts don’t work unless I reset them by disabling and enabling them. Since I am making a game like Clown Killing, I have the custom models parented in ServerStorage to be cloned from along with the animation scripts parented inside those custom models. Here is the script I have so far:

local player = game.Players.LocalPlayer
local hum = workspace[player.name]:WaitForChild("Humanoid")

hum.Running:Connect(function(speed)
	local p = Instance.new("Animation")
	p.AnimationId = "rbxassetid://4692455403"
	local loadanim = hum:LoadAnimation(p)
	if speed > 0 then
		loadanim:Play()
		print(speed)
	else
		loadanim:Stop()
		print(speed.." walking")
	end
end)

Thanks For Reading, And Any Help Is Appreciated! :grin:

First off, don’t do

local hum = workspace[player.name]:WaitForChild("Humanoid")

do

if not Player.Character then
Player.CharacterAdded:Wait()
end
while Player.Character.Parent ~= game.Workspace do -- Character isn't instantly added to workspace sometimes, LoadAnimation will error if humanoid not a descendant of workspace.
wait()
end
local hum = Player.Character:WaitForChild("Humanoid")

Also, do something like

p.Parent = hum

or something before :LoadAnimation(), not sure if the animation being parented to nil has an effect.

1 Like

The problem with this is like I said the game is like the Clown Killing game (I have a link above) which changes the character for when a round starts, this won’t work unless I disable and enable the script. Here is what I have in my ServerStorage:

Luigi's Mansion Scream Playground - Roblox Studio 2_15_2020 6_08_28 PM

I clone this model and set it to the character when they join a certain team for every round that goes through.

That isn’t my problem, I already have an animator for my custom Character all set up, while I was able to get the animation to work from cloning it to the character, thanks. But now the only problem I have is the the character won’t stop doing its animation when it stops running.

(I will be back after a while)

Is the print statement in the else block running?

yes, sorry for the long wait, I had to get some food.

I see the issue; The variables should be outside the function, like so:

local player = game.Players.LocalPlayer
local hum = workspace[player.name]:WaitForChild("Humanoid")
local p = Instance.new("Animation")
p.AnimationId = "rbxassetid://4692455403"
local loadanim = hum:LoadAnimation(p)

hum.Running:Connect(function(speed)
	if speed > 0 then
		loadanim:Play()
		print(speed)
	else
		loadanim:Stop()
		print(speed.." walking")
	end
end)

If the variable is inside, you’re creating a new track and stopping that. Also you’re creating and playing a new track everytime it runs. So, hopefully this should work.

1 Like

Thanks for the help, it worked! I set your last reply as the solution since it was the final thing that you posted which fixed my errors. Oh when I make simple errors, probably the most irritating thing I do with programming.

1 Like