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

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

Asked by 4 years ago
Edited 4 years ago

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?

0
I think you can use player from character lukebinno 53 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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)
0
Thanks! It worked perfectly! User#25281 0 — 4y
1
No problem! SimplifiedCode 227 — 4y
Ad

Answer this question