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?


local Tool = script.Parent local Player = game.Players.LocalPlayer.Character local script = Tool.TeleportScript function onActivation() local deb = false local x = math.random(1,991) local y = math.random(3,3) local z = math.random(1,991) local newPos = Vector3.new(x,y,z) if deb == false then deb = true local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") Player.HumanoidRootPart.Position = newPos Player.Humanoid:TakeDamage(25) wait(5) deb = false if Player.Humanoid.Health > 0 then script.Disabled = true else script.Disabled = false end end end Tool.Activated:Connect(onActivation)
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:

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

heres how you use the function:

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

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

    Contestants = 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