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

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

Asked by
Zero_Tsou 175
5 years ago
Edited 5 years ago

As the Title Says Lmao.

0
Player.Character ...? qChaos 86 — 5y
0
@qChaos Player is = game.players.localPlayer ? Zero_Tsou 175 — 5y
0
You can't access LocalPlayer from a server script Noxcitrus 2 — 3y

3 answers

Log in to vote
2
Answered by
BuDeep 214 Moderation Voter
5 years ago

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

0
Rep+ for adding links(and overall quality of answer), uncommon to see people adding links. BashGuy10 384 — 5y
0
^ Thanks :) BuDeep 214 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Everything about that is on Roblox Developer site https://developer.roblox.com/en-us/api-reference/class/Player Rafii2198 56 — 5y
Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
5 years ago

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

Answer this question