Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
Astralyst 389 Moderation Voter
6 years ago

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)
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" CreeperAssassin005 30 — 6y
0
I've also seen a script where it has a Instance.new("Animation"), should i add that? CreeperAssassin005 30 — 6y
0
Make sure the animation is owned by you, and it's not anyone elses, or else you'll get a permission error. Astralyst 389 — 6y
0
OMG THANK YOU SO MUCH!!!!! CreeperAssassin005 30 — 6y
Ad
Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
6 years ago

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")
Log in to vote
0
Answered by 6 years ago

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

Answer this question