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

How to get the Player's Character From a serverScript?

As the Title Says Lmao.

3 comments

0

Player.Character ...?

0

@qChaos Player is = game.players.localPlayer ?

0

You can't access LocalPlayer from a server script

3 answers

✓ Accepted answer

There's a few methods

From a ClickDetector:

workspace.Part.ClickDetector.MouseClick:connect(function(plr)
	local char = plr.Character
	--Do whatever
end)

From a Touched Event:

workspace.Part.Touched:connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		local char = plr.Character
		--Do whatever
	end
end)

Grabbing it on the player joining the game:

game.Players.PlayerAdded:connect(function(plr)
	repeat wait() until plr.Character
	local char = plr.Character
	--Do whatever
end)

Or if you know the players name:

local char = workspace['Player1']

Here are some links to some helpful wiki articles:

https://developer.roblox.com/en-us/api-reference/class/ClickDetector

https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded

https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched

2 comments

0

Rep+ for adding links(and overall quality of answer), uncommon to see people adding links.

0

^ Thanks :)

game.Players."PlayerName".Character This points to the character of the "PlayerName"

so you can do something like this (I will be the example):

local player = game.Players.Rafii2198.Character
player.Humanoid.NameDisplayDistance = 55
player.HumanoidRootPart.Position = player.HumanoidRootPart.Position + Vector3.new(0,10,0)

This will change the distance that other players will see my name to 55 (default is 100) and move me 10 studs up.

1 comment

0

Everything about that is on Roblox Developer site https://developer.roblox.com/en-us/api-reference/class/Player

Player has a property called Character. Indexing this property will return the player's associated character.

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