scriptingserver-siderobloxroblox-studio

Having an issue with a teleporting function on Roblox


The code is:

local function Teleport(TeleportPos)
  for i, Players in pairs(game.Players:GetPlayers)) do
    Players.Character:FindFirstChild(“HumanoidRootPart”).CFrame = TeleportPosition
   end
end

The code is a function to teleport all players in the game to a certain part

The problem is that whenever I run the function in the code by doing Teleport(ForestSpawn1.CFrame), nothing happens at all and I have no idea what to do.


Solution

  • That's because your function has the parameter TeleportPos and your code uses TeleportPosition when setting the Player position.

    Below I corrected the code to use the proper parameter name TeleportPos instead of TeleportPosition.

    local function Teleport(TeleportPos)
      for i, Players in pairs(game.Players:GetPlayers)) do
        Players.Character:FindFirstChild(“HumanoidRootPart”).CFrame = TeleportPos -- TeleportPos instead of TeleportPosition
       end
    end