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:
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local HoodUp= ReplicatedStorage.HoodUp local HoodDown= ReplicatedStorage.HoodDown local hoodupchar = ReplicatedStorage.HoodUpChar local hoodupcharclone = hoodupchar:Clone() HoodUp.OnServerEvent:Connect(function(Player, Name) local UserId = Players:GetUserIdFromNameAsync(Name) local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(UserId) Player.Character = hoodupcharclone end) HoodDown.OnServerEvent:Connect(function(Player, Name) local UserId = Players:GetUserIdFromNameAsync(Name) local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(UserId) Player:LoadCharacterWithHumanoidDescription(HumanoidDescription) end)
Client
local player = game.Players.LocalPlayer local character = player.Character repeat wait() character = player.Character until character local hum = character:WaitForChild("Humanoid") local emote = hum:LoadAnimation(script.Parent.Emote) playing = false character = false script.Parent.MouseButton1Click:connect(function() if playing == false then if character == false then emote:Play() playing = true wait(emote.Length - 0.1) local ReplicatedStorage = game:GetService("ReplicatedStorage") local ChangeCharacter = ReplicatedStorage.HoodUp script.Parent.MouseButton1Click:Connect(function() ChangeCharacter:FireServer(player) character = true end) wait(0.1) playing = false end end if playing == false then if character == true then emote:Play() playing = true wait(emote.Length - 0.1) local ReplicatedStorage = game:GetService("ReplicatedStorage") local ChangeCharacter = ReplicatedStorage.HoodDown script.Parent.MouseButton1Click:Connect(function() ChangeCharacter:FireServer(player) end) wait(0.1) playing = false end end end)
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:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") local animation = -- directory to the animation, if doesn't work use :WaitForChild to select it local track = animator:LoadAnimation(animation) Track:Play() -- 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:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local character = player.Character local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") local animation = -- directory to animation local Track = animator:LoadAnimation(animation) Track:Play() end) 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