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

How do you find a certain player's location?

Asked by
Mystdar 352 Moderation Voter
10 years ago

For example when they touch a block, or when they click a GUI something is moved to their location.

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Given a Player object, we can find the position of a part of them using their Character's Torso/Head's Position.

That would look like:

if player.Character and player.Character:FindFirstChild("Torso") then
    local position = player.Character.Torso.Position;
end

If, for example, we used a Touched event, then we would have a reference to their Character instead of their player.

We would have the choice to either 1) find the torso inside of that Character model or 2) find the Player from the character model and then repeat the above code.

1) Find torso from hit part

if hit.Parent and hit.Parent:FindFirstChild("Torso") then
    local position = hit.Parent.Torso.Position;
end

2) Find player from hit

if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
    local player = game.Players:GetPlayerFromCharacter(hit.Parent);
end


In all cases, position would be computed as a Vector3 value.

0
And then could I put in a clone script and make it's Vector3 that position (The model will be from the lighting) Mystdar 352 — 10y
0
Of course? BlueTaslem 18071 — 10y
Ad

Answer this question