How to get the head of the player who clicked a button

I want the player to hear a button click when they click the button, is there a way how?

2 Likes

the title and description ask 2 different questions

to get the head of the player who clicked a button, you would put this in a local script:

Script.Parent.MouseButton1Click:Connect(function() -- button location here
    local plr = game.Players.LocalPlayer
	local plrChar = plr.Character
	local head = plrChar:WaitForChild("Head")
    -- do whatever you want with the head here
end)

to play a click sound or any sound, simply insert the sound you want to play into StarterGui and put this in a local script:

ButtonLocation.MouseButton1Click:Connect(function() -- replace ButtonLocation with the location of the button, preferably in the button
     local plr = game.Players.LocalPlayer
     plr:WaitForChild("PlayerGui"):WaitForChild("SoundNameHere"):Play()
end)
1 Like

Ty!! I only needed the first script! Have a good day : D

1 Like

Um I have a little misfunction. Does the first script work for you?

replace the “ButtonLocation” to where the button is located.
what i would do is put the script in the button and do

Script.Parent.MouseButton1Click:Connect(function()
    local plr = game.Players.LocalPlayer
	local plrChar = plr.Character
	local head = plrChar:WaitForChild("Head")
    -- do whatever you want with the head here
end)

so place the local script inside of the button and replace the script with this, also make sure that the script is a LocalScript

My bad, I forgot it had to be a local script :white_check_mark::sweat_smile:

1 Like


Is there anything wrong with this script? I’m so thankful for your help. It shows this.

sorry, it should be:

Script.Parent.MouseButton1Click:Connect(function()
    local plr = game.Players.LocalPlayer
	local plrChar = plr.Character
	local head = plrChar:WaitForChild("Head")
    -- do whatever you want with the head here
end)

a little tired rn lol

2 Likes

I am so sorry! But it worked!! Tysm :DDD

2 Likes