I'm trying to make it so when you click a button your character does an animation and then his character is changed, when he does it again he goes back to his normal character.
Server:
01 | local Players = game:GetService( "Players" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local HoodUp = ReplicatedStorage.HoodUp |
04 | local HoodDown = ReplicatedStorage.HoodDown |
05 | local hoodupchar = ReplicatedStorage.HoodUpChar |
06 | local hoodupcharclone = hoodupchar:Clone() |
07 |
08 |
09 | HoodUp.OnServerEvent:Connect( function (Player, Name) |
10 | local UserId = Players:GetUserIdFromNameAsync(Name) |
11 | local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(UserId) |
12 |
13 | Player.Character = hoodupcharclone |
14 | end ) |
15 |
Client
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character |
03 | repeat wait() |
04 | character = player.Character |
05 | until character |
06 | local hum = character:WaitForChild( "Humanoid" ) |
07 | local emote = hum:LoadAnimation(script.Parent.Emote) |
08 | playing = false |
09 | character = false |
10 |
11 | script.Parent.MouseButton 1 Click:connect( function () |
12 | if playing = = false then |
13 | if character = = false then |
14 | emote:Play() |
15 | playing = true |
You know that you can just load the animation on the client because client animation replicates to the server so everyone can see it, right? Here is the client code:
1 | local player = game.Players.LocalPlayer |
2 | local character = player.Character or player.CharacterAdded:Wait() |
3 | local humanoid = character:WaitForChild( "Humanoid" ) |
4 | local animator = humanoid:WaitForChild( "Animator" ) |
5 | local animation = -- directory to the animation, if doesn't work use :WaitForChild to select it |
6 | local track = animator:LoadAnimation(animation) |
7 |
8 | Track:Play() |
9 | -- if you wanna put it in a event, just put that statement into the event, not the variables. |
Also if you wanna do it server-sided here is it:
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | player.CharacterAdded:Connect( function (character) |
03 | local character = player.Character |
04 | local humanoid = character:WaitForChild( "Humanoid" ) |
05 | local animator = humanoid:WaitForChild( "Animator" ) |
06 | local animation = -- directory to animation |
07 | local Track = animator:LoadAnimation(animation) |
08 |
09 | Track:Play() |
10 | end ) |
11 | end ) |
Why we don't use player.CharacterAdded:Wait() because the characteradded event is when the character is added, that means it already exists so we don't have to use the :Wait() like the client code.
Hope this helped :D