Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this teleporting script glitchy?

Asked by 8 years ago

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)
0
Try freezing the torso before cframing it shayner32 478 — 8y
0
add 7, not 4 on Line 15, 4 is silghtly inside the ground TheDeadlyPanther 2460 — 8y
0
The spawn itself is a few studs above any walkable surface. CoolJohnnyboy 121 — 8y

1 answer

Log in to vote
0
Answered by
Wutras 294 Moderation Voter
8 years ago

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. :)

Ad

Answer this question