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

Why is this Teleporting Script not Working?

This script is supposed to teleport the player, anchor their torso, give them a weapon and equip it for them, and then unanchor the torso.

However, the script doesn't teleport you; it does everything but that.

I have no idea why this script isn't working properly, and output gave me nothing.

Can someone please help me?

Here's the script:

local Player = script.Parent.Parent.Parent.Parent.Parent
local Primary = game.ReplicatedStorage.Guns.AK47: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.SSpawns:GetChildren()) do
		if v.Name == "SSpawn" then
			table.insert(spawns,v)
		end
	end
	torso.CFrame = spawns[math.random(1,#spawns)].CFrame
 + Vector3.new(0,4,0)
	wait(0.1)
	torso.Anchored = true
	wait(0.1)
	Primary.Parent = Player.Backpack
	Player.Character.Humanoid:EquipTool(Player:WaitForChild("Backpack"):WaitForChild(Primary.Name))
	wait(0.1)
	torso.Anchored = false
	script.Parent.Parent.Parent:remove()
end
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

2 answers

✓ Accepted answer

You cannot add a value to another value without defining which argument inside the value you're changing. Although, some things don't require you to define, it just automatically assumes what argument to use (normally just the first argument), like this:

torso.CFrame = spawns[math.random(1,#spawns)].Position + Vector3.new(0,4,0)

If you wanted to change more than just the position:

torso.CFrame = CFrame.new(spawns[math.random(1,#spawns)].Position, Vector3.new(0,0,0))

4 comments

0

Notice the ','

0

Thanks!

0

Wait, I still have the same issue in online mode. It won't teleport the player.

0

Press F9. It should come up with the dev console, and you can see the error.

There is an event called ":MoveTo" you could use that.

1 comment

0

What would the script look like in that case?

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