So I'm trying to make an animation button and I need to get a player's humanoid but I do not know how to get it. Here is the script:
script.Parent.MouseButton1Click:connect(function() local Dab = Humanoid:LoadAnimation(script.Dab) wait() Dab:Play() end)
I am aware I do not have a variable for the humanoid, and it is if you hit a gui text button you do an animation btw.
define player.
I believe(?) Animation should work properly with LocalScripts, so you can just go ahead and change that.
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function() if player.Character then -- to check if the character exists local Dab = player.Character.Humanoid:LoadAnimation(script.Dab) wait() Dab:Play() end end)
First, you should learn about game.Players.LocalPlayer. Then, you can reference the player's character and get th Humanoid from the character since it's a child of the character:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local humanoid = character:WaitForChild("Humanoid")
Make sure the script is a LocalScript.
Your player can then be found by using game.Players.LocalPlayer
, the character by game.Players.LocalPlayer.Character
and the humanoid by game.Players.LocalPlayer.Character.Humanoid
.
You'll need to make sure the character exists before creating the variable; else, you'll not have a character in the variable.
Here's an example:
local player = game.Players.LocalPlayer repeat wait() until player.Character local char = player.Character local hum = char.Humanoid
Hope this helped!
Thanks,
Explosion