I have a script which, when a player respawns and the boolean "EventEnabled" is true, the player should teleport to a random position on a part called "Pad", inside a model called "Box", found in the Workspace.
When the script runs, it does nothing, when it should. I've tried adding print statements to see if the script is accessing the player's character correctly, such as print(Character.Name)
or print(Character.HumanoidRootPart.Position)
, and it is accessing the player's character correctly. It just simply won't move the player, when it should.
This is the code I have:
game:GetService("Players").PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) if EventEnabled then local Pad = game:GetService("Workspace"):FindFirstChild("Box").Pad local MinX = Pad.Position.X - Pad.Size.X / 2 local MaxX = Pad.Position.X + Pad.Size.X / 2 local MinZ = Pad.Position.Z - Pad.Size.Z / 2 local MaxZ = Pad.Position.Z + Pad.Size.Z / 2 print(Character.Name) print(Character.HumanoidRootPart.Position) Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(math.random(MinX, MaxX), Pad.Position.Y + 3, math.random(MinZ, MaxZ))) end end) end
OK i'm making a shooting game and it teleports the player/players as well so here is how to do it
here is the script
this is just a teleport script
local LowerTorso = game.Players.LocalPlayer.Character:WaitForChild("Torso") --- if R15 change "Torso" to "LowerTorso" game:GetService("Players").PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) if EventEnabled then local num = math.random(1,6) --- change the 6 to how much pads there are DON'T THOUGH 1 LowerTorso.CFrame = CFrame.new(game.Workspace.Box["Pad"..num].Position) --- change the word "Pad" to the spawn/teleport thing's name