Here are my scripts:
wait() local CanEmote = true local Player = game.Players.LocalPlayer local character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = character.Humanoid local Animation = Humanoid:LoadAnimation(script.Animation) script.Parent.MouseButton1Click:Connect(function() if CanEmote then Animation:Play() CanEmote = false wait(1) CanEmote = true end end)
Can you help?
LocalScript
replicate to the server, as they are a part of player physics, just like how Humanoid
changes replicate to the server. You're getting that error because the character isn't loaded when the player joins the game, you'll have to wait for the character to load.wait() local Player = game.Players.LocalPlayer local character = Player.Character or Player.CharacterAdded:Wait() -- waiting for character local Humanoid = character.Humanoid local Animation1 = Humanoid:LoadAnimation(script.Animation1) local Animation2 = Humanoid:LoadAnimation(script.Animation2) local Animation3 = Humanoid:LoadAnimation(script.Animation3) local CanEmote = true script.Parent.MouseButton1Click:Connect(function() local emote = math.random(1,3) if emote == 1 and CanEmote then -- == true unnecessary Animation1:Play() CanEmote = false wait(2) CanEmote = true elseif emote == 2 and CanEmote then Animation2:Play() CanEmote = false wait(2) CanEmote = true elseif emote == 3 and CanEmote then Animation3:Play() CanEmote = false wait(2) CanEmote = true end end)
local
variables, as you didn't need to use them globally as they were defined at the top of the script.You should put this script in StarterPlayer > StarterCharacterScripts. What this will do will allow the script to load along the character ( the scripts load inside the character model in workspace ) and when you do this instead of using...
Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
You should use...
Humanoid = script.Parent:FindFirstChild("Humanoid")
But you should only use this when you have put the scirpt in the StarterCharacterScripts as it is already in the model which is why I done that.
****Another thing I saw
Also another thing, I was wondering if you wanted the animation to be seeable by other characters seeing as your game was FliteringEnabled, and if you wanted to do this you should use BindableEvents, https://wiki.roblox.com/index.php?title=API:Class/BindableEvent
This allows two scripts to communicate with each other regardless of it being local, server or module and by using this to your advantage, instead of using...
--Line 09, 16 and 22 btw Animation1:Play()
You should use...
--Wherever you put the BindableEvent, for my example case I put it in ServerStorage game:GetService("ServerStorage").BindableEvent:Fire(Animation1) --Sending an argument off
And in another server-script you can receive the firing of the event and play the animation e.g.
game:GetService("ServerStorage").BindableEvent.Event:connect(function(arg1) -- the arg we sent earlier arg1:Play() end)
I hope my answer helped or contributed to you. ~tantec