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

How can I find a player from his character?

Asked by 10 years ago

I know how to find a character from the player, but I can't do the opposite, help me please!

2 answers

Log in to vote
4
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

You'd need to use the GetPlayerFromCharacter method.

Here's an example..

1p = game.Players:GetPlayerFromCharacter(game.Workspace.Noob)
Ad
Log in to vote
-3
Answered by 10 years ago

Many ways first if we were to do it via LocalScript in StarterGui or StarterPack the script would look like this:

1Player = game.Players.LocalPlayer --Sets the LocalPlayer
2Character = Player.Character --Sets the Character

But this is only for LocalScripts what if we would want to run it from a Touched **event via **Script?

Hierarchy: game > Workspace > Part > Script

1script.Parent.Touched:connect(function(TouchedObject) --Creates Touched event function
2    Character = TouchedObject.Parent --Sets Character
3    if Character then --If Character is TouchedObject.Parent then proceed
4        Player = game.Players:GetPlayerFromCharacter(Character) --Gets Player from Character
5    end
6end)

There are also ways to do this via ClickDetector:

Hierarchy: game > Workspace > Part > ClickDetector > Script

1Clicker = script.Parent --Defines ClickDetector
2Clicker.MouseClick:connect(function(Player) --MouseClick event function
3    Char = Player.Character --Gets Character
4end)

Then there is of course the PlayerAdded/**CharacterAdded **events

1game.Players.PlayerAdded:connect(function(Player) --PlayerAdded event
2    Player.CharacterAdded:connect(function(Character) --Character Added event from Player
3        print(Character.Name)
4    end)
5end)
0
so much complex, and no need for it, you could even use a normal script at workspace and find it without using GetPlayerFromCharacter. marcoantoniosantos3 200 — 10y
0
I wrote this up late at night, got very bored so typed it. BosswalrusTheCoder 88 — 10y

Answer this question