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

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

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)

1 comment

0

Don't forget to accept my answer if it helps out.

2 answers

✓ Accepted answer

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)

3 comments

0

no u

0

rip

0

I truly appreciate it whenever someone helps me out, big thanks :D

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)

1 comment

0

heck

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