Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

The animation is playing but the character is not changing?

Asked by
FBS_8 25
3 years ago
Edited 3 years ago

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:

01local Players = game:GetService("Players")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local HoodUp= ReplicatedStorage.HoodUp
04local HoodDown= ReplicatedStorage.HoodDown
05local hoodupchar = ReplicatedStorage.HoodUpChar
06local hoodupcharclone = hoodupchar:Clone()
07 
08 
09HoodUp.OnServerEvent:Connect(function(Player, Name)
10    local UserId = Players:GetUserIdFromNameAsync(Name)
11    local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(UserId)
12 
13    Player.Character = hoodupcharclone
14end)
15 
View all 21 lines...

Client

01local player = game.Players.LocalPlayer
02local character = player.Character
03repeat wait()
04    character = player.Character
05until character
06local hum = character:WaitForChild("Humanoid")
07local emote = hum:LoadAnimation(script.Parent.Emote)
08playing = false
09character = false
10 
11script.Parent.MouseButton1Click:connect(function()
12    if playing == false then
13        if character == false then
14            emote:Play()
15            playing = true
View all 44 lines...

1 answer

Log in to vote
0
Answered by 3 years ago

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:

1local player = game.Players.LocalPlayer
2local character = player.Character or player.CharacterAdded:Wait()
3local humanoid = character:WaitForChild("Humanoid")
4local animator = humanoid:WaitForChild("Animator")
5local animation = -- directory to the animation, if doesn't work use :WaitForChild to select it
6local track = animator:LoadAnimation(animation)
7 
8Track: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:

01game.Players.PlayerAdded:Connect(function(player)
02player.CharacterAdded:Connect(function(character)
03local character = player.Character
04local humanoid = character:WaitForChild("Humanoid")
05local animator = humanoid:WaitForChild("Animator")
06local animation = -- directory to animation
07local Track = animator:LoadAnimation(animation)
08 
09Track:Play()
10end)
11end)

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

0
thanks i'm going to try to make it work FBS_8 25 — 3y
0
wait how would i make it so he can toggle on a character and toggle off a character? FBS_8 25 — 3y
0
I edited my post so you can see the client sided script FBS_8 25 — 3y
Ad

Answer this question