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

Why is this teleporting script glitchy?

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

0

Try freezing the torso before cframing it

0

add 7, not 4 on Line 15, 4 is silghtly inside the ground

0

The spawn itself is a few studs above any walkable surface.

1 answer

Try this:

local spawn = spawns[math.random(1, #spawns)]
spawn.CanCollide = false
torso.CFrame = spawn.CFrame*CFrame.new(0, torso.Parent["Left Leg"].Size.Y, 0)

This would simply create the variable spawn to show the script what has been chosen as spawn and disable the spawn's collision. Then it would change the torso's CFrame to make the character stand on the spawn.

Hope this helped. :)

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