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.

01local a = Instance.new("Part", game.Workspace)
02a.Name = "Teleport"
03a.Position = Vector3.new(-5.848, 13, -95.462)
04a.Anchored = true
05local b = Instance.new("ClickDetector", a)
06function playermover(hit)
07local torso = hit.Torso
08torso.Position = CFrame3.new(7, 5, -55)
09end
10game.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.

01local a = Instance.new("Part", workspace)
02a.Name = "Teleport"
03a.Position = Vector3.new(-5.848, 13, -95.462)
04a.Anchored = true
05 
06local b = Instance.new("ClickDetector", a)
07 
08function playermover(hit) --'hit' would be the Player
09    local torso = hit.Character.Torso --Player.Character.Torso is Torso.
10    torso.CFrame  = CFrame.new(7, 5, -55) --CFrame them so they won't die.
11end
12 
13workspace.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