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

how to play a animation after i changed my player's character?

rs = game:GetService("ReplicatedStorage")
ss = game:GetService("ServerStorage")

rs.q.OnServerEvent:Connect(function(player)
	local Cac = player.Character
    local Hum = Cac.Humanoid
    local P1 = Hum:LoadAnimation(script.Animation)
	local NewChar = ss.Rogue:Clone()
	local Pos = player.Character:GetPrimaryPartCFrame()
	player.Character :Destroy()
	player.Character = NewChar
	NewChar.Parent = workspace
	NewChar:SetPrimaryPartCFrame(Pos)
	wait(1)
	P1:Play() 
	Hum.Walkspeed = 0
	wait(4)
	Hum.Walkspeed = 30
	P1:Stop()
	
end)

so basically i want it so after i changed my player's character it plays a animation and a sound(forgot to add sound) but anyhow this is the script and how i tried to do it any help is apreciated

1 answer

✓ Accepted answer

I believe the problem is that you have to define humanoid as the humanoid of the new character you inserted.

Try defining the local variable humanoid as the rig character’s humanoid.

For adding sound/animations look below:

Check this out: https://developer.roblox.com/en-us/api-reference/class/Sound

Create a sound with Instance.new,

Set the SoundId to the sound ID you want to play

Set its parent to where you want to play, if its not in a part, it’ll probably play for the player to hear without coming from an object.

Then you can use :Play() to play the sound and :Stop() to stop it.

-- local script example
local sound = Instance.new(“Sound”)
sound.SoundId = “rbxassetid://yourNumberID”
sound.Parent = game.Players.LocalPlayer.PlayerGui
sound:Play()

Skip below if you already know how to play animations:

To play, an animation check this article out: https://developer.roblox.com/en-us/articles/using-animations-in-games

You would create an animation and set the id similar to the sound example:

local anim = Instance.new(“Animation”)
anim.AnimationId = “rbxassetid://exampleID”

Then load it into the Humanoid to get an AnimationTrack to use:

local animation = humanoid:LoadAnimation(anim) -- define humanoid
animation:Play()

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