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

How Do I Make A Team Deploy Script?

So basically, When you click deploy you will spawn into a random team spawn location. If that didn't make sense ------ | | | 1.There are two teams and different spawn locations for each team. 2. When you click the deploy button i want it to spawn you to one of your team spawn locations. 3. And i want the script to randomly pick a spawn location.

HasPressedTeleport = false


function TeleportPlayer()
	if HasPressedTeleport == false then
		Player.Character:MoveTo(SpawnLocation)-- How would i make the script spawn
	end                                      							 -- you to your teams spawnlocation
end                                           							-- and make it randomize it.....

1 answer

NOTE: When a player spawns, they spawn in a black box, then a gui will appear from StarterGui. Every black box has

The game's hierarchy:

  • Workspace
    • SpawnBox
      • Part
      • Part
      • etc.
      • RedSpawn (same TeamColor as RedTeam, this is where the players spawn)
      • BlueSpawn (same TeamColor as BlueTeam, this is where the players spawn)
    • RedSpawns (model)
      • SpawnBlock (where they spawn)
      • SpawnBlock
      • etc.
    • BlueSpawns
      • SpawnBlock
      • SpawnBlock
      • etc.
  • StarterGui
    • SpawnGui
      • Frame
        • TextButton (called 'JoinButton')
  • Teams
    • RedTeam
    • BlueTeam
local team1 = game.Teams.RedTeam
local team2 = game.Teams.BlueTeam

local spawns1 = game.Workspace.RedSpawns:GetChildren() -- gets a table of all the spawns
local spawns2 = game.Workspace.BlueSpawns:GetChildren()

function teleportPlayer(player,team) -- function for teleporting the player
	if player.Character then
		local char = player.Character -- the player's character
		if team == team1 then
			char.Torso.CFrame = spawns1[math.random(1,#spawns1)].Position + Vector3.new(0,7,0) -- teleports the player
		elseif team == team2 then
			char.Torso.CFrame = spawns2[math.random(1,#spawns2)].Position + Vector3.new(0,7,0)
		end
	end
end

function setUp(player) -- setup function
	if player.TeamColor == team1.TeamColor then
		teleportPlayer(player,team1) -- calls the teleporting function
	elseif player.TeamColor == team2.TeamColor then
		teleportPlayer(player,team2)
	end
end

game.Players.PlayerAdded:connect(function(p) -- when a player joins
	p.CharacterAdded:connect(function() -- when the player's character spawns
		local gui = p.PlayerGui:WaitForChild("SpawnGui") -- finds the gui
		if gui then
			gui.Frame.JoinButton.MouseButton1Down:connect(function() -- when joinbutton is clicked
				setUp(p) -- calls the setup function	
				gui:remove() -- deletes the gui so the user can play	
			end)
		end
	end)
end)

It looks daunting because of it's size, but this is actually pretty simple. Hope I helped. Any questions, PM EmeraldSlash on ROBLOX (my main).

31 comments

0

Is this in a local script?

0

No, it's in a Script inside Workspace.

0

where do i put the script?

0

Inside Workspace... I just said that.

0

hmm its not working i thing i did something wrong

0

... Read the output. It's probably because you named something wrong in Workspace, Teams, or StarterGui.

0

thank you for helping me so far i must be a pain

0

np, i do this all the time xD

0

im not sure what i did wrong?!?!?

0

Read the output. I got to go now, ask another question.

0

16:24:38.625 - Workspace.Script:34: ')' expected (to close '(' at line 30) near 'end' thats what it said

0

fixed it, copy from lines 26 and down

0

thanks

0

Workspace.SpawnScript:8: attempt to index global 'p' (a nil value) huhhhhhhhhhh another problem

0

18:03:05.191 - Workspace.SpawnScript:8: attempt to index global 'p' (a nil value) 18:03:05.192 - Stack Begin 18:03:05.192 - Script 'Workspace.SpawnScript', Line 8 - global teleportPlayer 18:03:05.193 - Script 'Workspace.SpawnScript', Line 20 - global setUp 18:03:05.193 - Script 'Workspace.SpawnScript', Line 31 18:03:05.193 - Stack End

0

if this doesn't work ill still give you a reputation

0

fixed again, hopefully it wokrs properly now.

0

OMG...

0

23:03:47.635 - Workspace.SpawnScript:8: attempt to index global 'p' (a nil value) 23:03:47.635 - Stack Begin 23:03:47.636 - Script 'Workspace.SpawnScript', Line 8 - global teleportPlayer 23:03:47.636 - Script 'Workspace.SpawnScript', Line 20 - global setUp 23:03:47.637 - Script 'Workspace.SpawnScript', Line 31 23:03:47.637 - Stack End

0

Failed, again. I'm bad at this doing stuff witohut using studio. Fixed again

0

18:15:13.610 - Workspace.SpawnScript:11: bad argument #3 to 'CFrame' (CFrame expected, got Vector3) 18:15:13.610 - Script 'Workspace.SpawnScript', Line 11 - global teleportPlayer 18:15:13.611 - Script 'Workspace.SpawnScript', Line 20 - global setUp 18:15:13.611 - Script 'Workspace.SpawnScript', Line 31 18:15:13.611 - Stack End

0

That's weird, because there is no 'argument #3'. I'll test asap.

0

lol thanks for helping me so far

0

np lol

0

did it work when you tested it?

0

haven't tested properly yet, will do that in a few days, sorry

0

np thank you so far.... I know i said this a lot but thx so much!!!!

0

What if it says this

0

15:27:53.211 - RedTeam is not a valid member of DataModel 15:27:53.213 - Stack Begin 15:27:53.214 - Script 'Workspace.Script', Line 1 15:27:53.215 - Stack End

0

I fixed it

0

It isn't saying anything in output but its not working

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