Answered by
4 years ago Edited 4 years ago
The problem here is that you are indexing character with humanoid, and sometimes it doesn't exist and may error.
To fix this you could wait for the character and humanoid, maybe doing this.
1 | local character = players.LocalPlayer.CharacterAdded:Wait() |
Wich is better than using repeat wait() until character
So, implementing this to your code.
01 | local players = game:GetService( "Players" ) |
02 | local player = players.LocalPlayer |
03 | local character = player.CharacterAdded:Wait() or player.Character |
04 | local humanoid = character:WaitForChild( "Humanoid" ) |
05 | local mouse = player:GetMouse() |
06 | local saluteButton = player:WaitForChild( "PlayerGui" ).MobileEmotes.Salute |
08 | local anim = Instance.new( "Animation" ) |
12 | local function onClick() |
13 | local playAnim = humanoid:LoadAnimation(anim) |
17 | saluteButton.MouseButton 1 Click:Connect(onClick) |
If this answered your question then mark it as the answer, it would be highly appreciated!