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

Murder game teleport not working?

I am making a murder type game, I have no clue how to make it so that it teleports players, but have attempted it. Here is the code.

--SpyxSpy main script

local spawns = {"Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6"}

local selectedSpawn = spawns[math.random(1, #spawns)]

local Teleport = selectedSpawn

local spawn = workspace[selectedSpawn]

local Roles = {"Scientist", "Spy", "Soldier"}
local RoleMaxes = {6, 1, 2, 1}
local filled = {0, 0, 0, 0}
local function chooseRole()
    local open = {}
    for i = 1, #Roles do
        if filled[i] < RoleMaxes[i] then
            table.insert(open, i)
        end
    end
    local randomOpen = open[math.random(1, #open)]
    filled[randomOpen] = filled[randomOpen] + 1
    return Roles[randomOpen]
end

local selectedRole = chooseRole()
print(selectedRole)
if selectedRole == "Scientist" then
	game.StarterGui.ClassGui.Frame.TextLabel.TextSize = 50
	game.StarterGui.ClassGui.Frame.TextLabel.Text = "Scientist, stick with soldiers!"
	wait(2)
	game.StarterGui.ClassGui.Frame.Visible = false
end
if selectedRole == "Soldier" then
	game.StarterGui.ClassGui.Frame.TextLabel.TextSize = 50
	game.StarterGui.ClassGui.Frame.TextLabel.Text = "Soldier, protect scientists against the spy!"
	wait(2)
	game.StarterGui.ClassGui.Frame.Visible = false
end
if selectedRole == "Spy" then
	game.StarterGui.ClassGui.Frame.TextLabel.TextSize = 50
	game.StarterGui.ClassGui.Frame.TextLabel.Text = "Spy, kill soldiers and scientists, and gather data!"
	wait(2)
	game.StarterGui.ClassGui.Frame.Visible = false
end
local Pos = script.Parent.Parent:findFirstChild(Teleport)
Player:moveTo(Pos.Position)

1 answer

To make the game teleport players, you have to change the location of the HumanoidRootPart of the player. The HumanoidRootPart is an invisible part that is the core of the player. If you change the location of it, then the rest of the player will follow it. Now, how do we do that?

The HumanoidRootPart's location is based off of a CFrame location. To change the CFrame, you need to give it an XYZ value.

Let's say you're teleporting players from their client.

local player = game.Players.LocalPlayer --Define the local player

player.Character.HumanoidRootPart.CFrame = CFrame.new(Insert the position that you want the player to teleport to.) Ex: (42, 56, 13)

For your game in each if-statement, you would need to have a different position of teleportation.

Hope this helped and happy coding!

1 comment

0

Feel free to ask any questions!

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