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

Making a randomized teleporter GUI but when i click it, it does not teleport?

Hello, i am making a First Person Shooter where you start off in a room, but when the next match comes, you click join, and you join the next map. for some reason I'm having troubles with the teleporting GUI. here is my Teleporter script:

if script.Parent.JoinButton.Text == "Join" then
player = game.Players.LocalPlayer
s1 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint 
s2 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint2
s3 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint3
s4 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint4
s5 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint5
s6 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint6
s7 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint7
s8 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint8
s9 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint9
s10 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint10
s11 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint11
s12 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint12
s13 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint13
s14 = game.Workspace.GiantRoom.SpawningPoints.SpawningPoint14
--VARIABLES for spawn points on map
	
end

if script.Parent.JoinButton.Text == "Join" then
	 Spn = math.random(1,2)
	if spn == 1 then
		function Teleport()
	  player.Character.Torso.Position = s1.Position + Vector3.new(0,5,0)
	  
	  end
	script.Parent.JoinButton.MouseButton1Down:connect(Teleport)
	end
	if spn == 2 then
	  function TeleportTwo()
	 player.Character.Torso.Position = s2.Position + Vector3.new(0,5,0)
	  end
	script.Parent.JoinButton.MouseButton1Down:connect(TeleportTwo)
	end
end
-- Random Spawn Teleporter

3 comments

0

Use a for loop it iterate through the "SpawnPoints" object & have the children be added to a table, instead of doing lines 3-16.

0

when i use torso.Position it kills me. instead use CFrame, it moves the whole body at the same time. tho for the no teleporting part, idk how i can help, i never made a teleporter.

0

ok, thanks for the info

1 answer

✓ Accepted answer

It appears your current knowledge doesn't know how to use things like GetChildren() and where to put events. Below is spoon feeding code, which I only do with people who are less then 20 rep as usually they don't have much code experience like you currently do.

Below is a fixed version of your code and if you feel like improving yourself look through some of these methods in the Roblox wiki and newer ones you want/need to learn about. it is the best resource and recommend you use it.

Just know if you copy this code and just use it you aren't helping yourself.

script.Parent.JoinButton.MouseButton1Down:Connect(function() -- What is inside will execute whenever the button is clicked, NEVER put events like this inside of an if statement
	if script.Parent.JoinButton.Text == "Join" then -- You can click on this button whenever, but if the text isn't "Join" then nothing will happen
		player = game.Players.LocalPlayer
		
		--It is a bad practice of listing out every spawn/child as it's own variable to randomly select it
		
		allMapSpawns = workspace.GiantRoom.SpawningPoints:GetChildren() -- This will get all the items inside of whatever you have GetChildren() on front of
	    randomSpawn = allMapSpawns[math.random(1, #allMapSpawns)] -- This randomly selects a child, or in this case a part, inside of that table which is above
		
		--It is recommended to use MoveTo() over changing the position of the torso and I believe changing the torso's CFrame is prefered over that, but I will let you use something more basic for your current knowledge
		player.Character:MoveTo(randomSpawn.Position + Vector3.new(0, 5, 0))
		
		-- Hey! The script looks easier to read too. :D
	end
end)

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