(Sorry if this is the wrong category, its only my 2nd post to the DevForum, so I don’t know much about the categories etc.)
I am trying to make a rig that only 1 player plays as. I am trying to animate it, but I don’t want to put its animation script into StarterCharacterScripts, because that would then override the other player’s animations.
I currently have an idle and walking animation, here is the script:
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
--Animations
local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack = hum.Animator:LoadAnimation(idleAnim)
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = hum.Animator:LoadAnimation(walkAnim)
hum.Running:Connect(function(speed)
if speed > 0 then
if idleAnimTrack.IsPlaying then
idleAnimTrack:Stop()
end
if not walkAnimTrack.IsPlaying then
walkAnimTrack:Play()
end
else
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if not idleAnimTrack.IsPlaying then
idleAnimTrack:Play()
end
end
end)
This is a LocalScript named ‘Animate’. It doesn’t work when I put it directly into the rig, and when I put it in StarterCharacterScripts, only the walk animation works.
So my question is: How can I make this animation script only apply to the player with the rig, and what can I do to make the idle animation play?
(I am currently using the rig as a starter character, just until I can get this working)
Problem 1 can be fixed by using your code in a normal Script instance for NPCs in the server. LocalScripts don’t work on servers, only the players’ devices (clients).
Problem 2 can also be fixed by not using Running. Use RunService.RenderStepped (for client) or Stepped (for server, NPCs), and the Humanoid’s MoveDirection.
-- for localscript
local function Update(Speed)
if Speed > 0 then
if idleAnimTrack.IsPlaying then
idleAnimTrack:Stop()
end
if not walkingAnimTrack.IsPlaying then
walkAnimTrack:Play()
end
else
if not idleAnimTrack.IsPlaying then
idleAnimTrack:Play()
end
if walkingAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
end
end
game:GetService("RunService").RenderStepped:Connect(function()
Update(YourHumanoidHere.MoveDirection.Magnitude)
end
Both of the animations now work, so thank you for that!
But I tried using a server script for it, and it didn’t work. You mentioned NPC’s, so I just want to say that this doesn’t involve NPC’s. At the start of the round, 1 player is the rig, while the others are their normal characters, sort of like in Piggy. I need the player with the rig to have this separate animation script, but let the others keep the default Roblox one.
Ahh… I see. Animations can replicate if an Animator or Humanoid instance is a descendant of Player.Character. Have you tried replacing the character of the Player? If not, you can just spawn the chosen player by doing Player.Character = Your Rig and removing the old character.