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

Help w Teleportation?

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

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)

3 comments

0

Bruhhh thank you so much fr

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'!

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.

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