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

Help w Teleportation?

Asked by 10 years ago

I would like to know how to get the players torso. I understand that the player that is indexed in this script is the one here: game.Players.Player but I would like to know how to get the one indexed in game.Workspace.Player.

local a = Instance.new("Part", game.Workspace)
a.Name = "Teleport"
a.Position = Vector3.new(-5.848, 13, -95.462)
a.Anchored = true
local b = Instance.new("ClickDetector", a)
function playermover(hit)
local torso = hit.Torso
torso.Position = CFrame3.new(7, 5, -55)
end
game.Workspace.Teleport.ClickDetector.MouseClick:connect(playermover)

1 answer

Log in to vote
3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

The Player in workspace is called your Player's Character

To access it, you index the Player like; Player.Character, and it will get the Character in Workspace.

local a = Instance.new("Part", workspace)
a.Name = "Teleport"
a.Position = Vector3.new(-5.848, 13, -95.462)
a.Anchored = true

local b = Instance.new("ClickDetector", a)

function playermover(hit) --'hit' would be the Player
    local torso = hit.Character.Torso --Player.Character.Torso is Torso.
    torso.CFrame  = CFrame.new(7, 5, -55) --CFrame them so they won't die.
end

workspace.Teleport.ClickDetector.MouseClick:connect(playermover)
0
Bruhhh thank you so much fr Ethan_Waike 156 — 10y
1
`hit` is a bad name for that parameter, since it is equal to the Player object that clicked. `hit` makes me think you're going to connect to it a Touched event or something. Since nothing is hit, don't name it 'hit'! Perci1 4988 — 10y
0
It doesn't exactly matter what you name the parameter, but yes it's good practice to name them accordingly to the event / function. Goulstem 8144 — 10y
Ad

Answer this question