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

(Answered)How would I get a character from a Click Detector in a local script?

So I have a local script inside starter GUI. I also have a part with a click detector in workspace. My Code in StarterGUI:

game.Workspace.Part.ClickDetector.MouseClick:Connect(function(p)
	p.Parent.Head.Transparency = 1
	
end)

The thing is, inside a local script in starter gui, you can't get the player by using p.Parent in this case. So how would I make it so that in a local script in starter gui would make something happen to the player that only that player can see?

1 comment

0

I think you can use player from character

1 answer

✓ Accepted answer

You can get the player by using "game:GetService("Players").LocalPlayer" and you can get the character from that player by using "game:GetService("Players").LocalPlayer.Character". Here's an example:

game.Workspace.Part.ClickDetector.MouseClick:Connect(function()
local player = game:GetService("Players").LocalPlayer
local character = game:GetService("Players").LocalPlayer.Character
character.Head.Transparency = 1
end)

2 comments

0

Thanks! It worked perfectly!

1

No problem!

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