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

How do I teleport a player?

Asked by 4 years ago

Ok so my goal is to onActivation of the tool to take away 25 hp and teleport the player.

Problem is it does teleport the player however it makes the invisible/completely transparent and flings them whenever they move.

Are there any alternative solution to the script I made so I can safely teleport the player without it going invisible nor flinging?

01local Tool = script.Parent
02local Player = game.Players.LocalPlayer.Character
03 
04local script = Tool.TeleportScript
05 
06function onActivation()
07    local deb = false
08    local x = math.random(1,991)
09    local y = math.random(3,3)
10    local z = math.random(1,991)
11    local newPos = Vector3.new(x,y,z)
12 
13    if deb == false then
14        deb = true
15        local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
View all 29 lines...
0
You should use CFrame.new(x,y,z) instead of Vector3.new(x,y,z). Adding to that, you should also use Player.HumanoidRootPart.CFrame = newPos instead. RazzyPlayz 497 — 4y

2 answers

Log in to vote
0
Answered by
NEILASc 84
4 years ago
Edited 4 years ago

You Change The Position Of The HumanoidRootPart Since It Has A Motor6D to The Torso. Motor6D Acts Like Welds When You Move Them Using Your Move Tool But You Can Use CFrame! Example:

1local function teleportPlayers(availablePlayers,spawns) -- availablePlayers: Table / spawns: part
2    for _, plr in pairs(availablePlayers) do
3        if plr.Character then
4                plr.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,5,0)
5        end
6    end
7end

heres how you use the function:

1teleportPlayers(Contestants,workspace.Lobby.SpawnLocation:GetChildren())

But Before You Do That You Need To Add Every Single Player To A Table:

1Contestants = game.Players:GetPlayers() -- returns a table of all the players
Ad
Log in to vote
0
Answered by 4 years ago

~ --- might work ~~~~~~~~~~~~~~~~ script.Parent.Touched:Connect(function(hit) local player = hit.Parent if player then local torso = player.HumanoidRootPart if torso then torso.Position = Vector3.new(-308.222, 81.791, -1039.963) --- Put your position end end end)

~~~~~~~~~~~~~~~~~

Answer this question