So this teleporting script is supposed to teleport a player to the game and give them their weapon and equip it.
The script works fine, but it tends to have this glitch where it will fling people out of the map. It's relatively common, and I don't know how to stop it besides adding invisible ceilings to the map.
Can someone please help me?
Here's the script:
local Player = script.Parent.Parent.Parent.Parent.Parent
local Primary = game.ReplicatedStorage.Guns.Pistol:Clone()
function onButtonClicked()
if game.Workspace.Playing.Value == true then
Player.CameraMode = "LockFirstPerson"
Player.Backpack.Teled.Value = true
local torso = Player.Character.Torso
spawns = {}
for i,v in ipairs(game.Workspace.Map.Spawns:GetChildren()) do
if v.Name == "Spawn" then
table.insert(spawns,v)
end
end
torso.CFrame = spawns[math.random(1,#spawns)].CFrame
+ Vector3.new(0,4,0)
Primary.Parent = Player.Backpack
Player.Character.Humanoid:EquipTool(Player:WaitForChild("Backpack"):WaitForChild(Primary.Name))
script.Parent.Parent.Parent:remove()
end
end
script.Parent.MouseButton1Click:connect(onButtonClicked)

3 comments
Try freezing the torso before cframing it
add 7, not 4 on Line 15, 4 is silghtly inside the ground
The spawn itself is a few studs above any walkable surface.