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
local team1 = game.Teams.RedTeam
local team2 = game.Teams.BlueTeam
local spawns1 = game.Workspace.RedSpawns:GetChildren()
local spawns2 = game.Workspace.BlueSpawns:GetChildren()
function teleportPlayer(player,team)
if player.Character then
local char = player.Character
if team == team1 then
char.Torso.CFrame = spawns1[math.random(1,#spawns1)].Position + Vector3.new(0,7,0)
elseif team == team2 then
char.Torso.CFrame = spawns2[math.random(1,#spawns2)].Position + Vector3.new(0,7,0)
end
end
end
function setUp(player)
if player.TeamColor == team1.TeamColor then
teleportPlayer(player,team1)
elseif player.TeamColor == team2.TeamColor then
teleportPlayer(player,team2)
end
end
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function()
local gui = p.PlayerGui:WaitForChild("SpawnGui")
if gui then
gui.Frame.JoinButton.MouseButton1Down:connect(function()
setUp(p)
gui:remove()
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
Is this in a local script?
No, it's in a Script inside Workspace.
where do i put the script?
Inside Workspace... I just said that.
hmm its not working i thing i did something wrong
... Read the output. It's probably because you named something wrong in Workspace, Teams, or StarterGui.
thank you for helping me so far i must be a pain
np, i do this all the time xD
im not sure what i did wrong?!?!?
Read the output. I got to go now, ask another question.
16:24:38.625 - Workspace.Script:34: ')' expected (to close '(' at line 30) near 'end' thats what it said
fixed it, copy from lines 26 and down
thanks
Workspace.SpawnScript:8: attempt to index global 'p' (a nil value) huhhhhhhhhhh another problem
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
if this doesn't work ill still give you a reputation
fixed again, hopefully it wokrs properly now.
OMG...
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
Failed, again. I'm bad at this doing stuff witohut using studio. Fixed again
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
That's weird, because there is no 'argument #3'. I'll test asap.
lol thanks for helping me so far
np lol
did it work when you tested it?
haven't tested properly yet, will do that in a few days, sorry
np thank you so far.... I know i said this a lot but thx so much!!!!
What if it says this
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
I fixed it
It isn't saying anything in output but its not working