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

How Do I Make A Team Deploy Script?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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

0
Is this in a local script? xShadowNight 20 — 8y
0
No, it's in a Script inside Workspace. TheDeadlyPanther 2460 — 8y
0
where do i put the script? xShadowNight 20 — 8y
0
Inside Workspace... I just said that. TheDeadlyPanther 2460 — 8y
View all comments (27 more)
0
hmm its not working i thing i did something wrong xShadowNight 20 — 8y
0
... Read the output. It's probably because you named something wrong in Workspace, Teams, or StarterGui. TheDeadlyPanther 2460 — 8y
0
thank you for helping me so far i must be a pain xShadowNight 20 — 8y
0
np, i do this all the time xD TheDeadlyPanther 2460 — 8y
0
im not sure what i did wrong?!?!? xShadowNight 20 — 8y
0
Read the output. I got to go now, ask another question. TheDeadlyPanther 2460 — 8y
0
16:24:38.625 - Workspace.Script:34: ')' expected (to close '(' at line 30) near 'end' thats what it said xShadowNight 20 — 8y
0
fixed it, copy from lines 26 and down TheDeadlyPanther 2460 — 8y
0
thanks xShadowNight 20 — 8y
0
Workspace.SpawnScript:8: attempt to index global 'p' (a nil value) huhhhhhhhhhh another problem xShadowNight 20 — 8y
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 xShadowNight 20 — 8y
0
if this doesn't work ill still give you a reputation xShadowNight 20 — 8y
0
fixed again, hopefully it wokrs properly now. TheDeadlyPanther 2460 — 8y
0
OMG... xShadowNight 20 — 8y
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 xShadowNight 20 — 8y
0
Failed, again. I'm bad at this doing stuff witohut using studio. Fixed again TheDeadlyPanther 2460 — 8y
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 xShadowNight 20 — 8y
0
That's weird, because there is no 'argument #3'. I'll test asap. TheDeadlyPanther 2460 — 8y
0
lol thanks for helping me so far xShadowNight 20 — 8y
0
np lol TheDeadlyPanther 2460 — 8y
0
did it work when you tested it? xShadowNight 20 — 8y
0
haven't tested properly yet, will do that in a few days, sorry TheDeadlyPanther 2460 — 8y
0
np thank you so far.... I know i said this a lot but thx so much!!!! xShadowNight 20 — 8y
0
What if it says this JEHL2008 -5 — 4y
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 JEHL2008 -5 — 4y
0
I fixed it JEHL2008 -5 — 4y
0
It isn't saying anything in output but its not working JEHL2008 -5 — 4y
Ad

Answer this question