Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you find a player's humanoid using a GUI script?

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.

3 answers

✓ Accepted answer

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)

4 comments

0

When I do this is says, "Animation "https://www.roblox.com///asset/?id=1241910613&serverplaceid=0" failed to load in "Players.CreeperAssassin005.PlayerGui.ScreenGui.Frame.TextButton.LocalScript.Dab.AnimationId": Animation failed to load"

0

I've also seen a script where it has a Instance.new("Animation"), should i add that?

0

Make sure the animation is owned by you, and it's not anyone elses, or else you'll get a permission error.

0

OMG THANK YOU SO MUCH!!!!!

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

This discussion is preserved as it was. New answers, comments, and votes are closed.