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

How do I access the players humanoid when I click a button?

Asked by 5 years ago

How do I access a player's HUMANOID when I click. This question is simply how do I find the player that is clicking the button and access their humanoid?

part = script.Parent

function Activated(click) if game.Workspace.--where is the player located?!?-- then Humanoid.WalkSpeed = 100 else print("False") end end

script.Parent.ClickDetector.MouseClick:Connect(Activated)

0
Don't forget to accept my answer if it helps out. User#24403 69 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

For future reference

When asking/answering questions remember to put the code in a code block.

To put your code in a code block, click the Lua icon that is above the question/answer box. This will generate lines of tildes (~~~~) to paste the code in between the tildes.

Answer to your question

By default, the argument passed to your event listener is the player who clicked the button. With that in mind, you can use player.Character.Humanoid to get the humanoid.

local part = script.Parent -- # always use local variables

local function Activated(player)
    player.Character.Humanoid.WalkSpeed = 100
end

part.ClickDetector.MouseClick:Connect(Activated)
0
no u xPolarium 1388 — 5y
0
rip TheluaBanana 946 — 5y
0
I truly appreciate it whenever someone helps me out, big thanks :D popdrinkman 8 — 5y
Ad
Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago

The 'click' parameter, as you have it, is the player that clicked. You can access their character just by doing click.Character then path to the Humanoid:

local part = script.Parent
local cd = part.ClickDetector

cd.MouseClick:Connect(function(playerWhoClicked)
    playerWhoClicked.Character.Humanoid.WalkSpeed = 100
end)
0
heck User#24403 69 — 5y

Answer this question