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

Team Specific Lobby Script (help?)

If someone could help me that would be great! I was wondering if someone could help me modify this script to that It has red and blue team spawns and when the round starts it gives team-specific weapons from lighting or some other place and then when the round ends it takes away the weapons.

local oldMessage = ""
local minPlayers = 2
 
function teleportAllPlayers()
	local target = CFrame.new(workspace.TeleportTarget.Position)
	for i, player in ipairs(game.Players:GetChildren()) do
		player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
		player.Playing.Value = 1
		--add an offset of 5 for each character
	end
end
 
function message(message)
	if oldMessage ~= message then
		oldMessage = message
		print(message)
	end
end
 
function playersCurrentlyPlaying()
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.Playing.Value == 1 then return true end
	end
	return false
end
 
game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			player.Playing.Value = 0
		end)
	end)
 
	local playing = Instance.new("IntValue", player)
	playing.Value = 0
	playing.Name = "Playing"
end)
 
 
while(true) do
	wait(10)
	if #game.Players:getPlayers() >= minPlayers then
		if playersCurrentlyPlaying() then
			message("Waiting for the current game to end...")
		else
			message("There are enough players for a new game!  Teleporting...")
			wait(4)
			teleportAllPlayers()
		end
	else message("Waiting for more players...") end
end

2 answers

Make a function for when the round starts. Put the items you want for the player in a folder in ReplicatedStorage. In the function that runs when the round has started put this.

--//Services
local RepStorage = game:GetService("ReplicatedStorage")
local teams = game:GetService("Teams")

--//Teams
local teamblue = Instance.new("Team")
teamblue.Name = "TeamBlue"
teamblue.Parent = teams
teamblue.TeamColor = BrickColor.new("Really blue") 
local teamred = Instance.new("Team")
teamred.Name = "TeamRed"
teamred.Parent = teams
teamred.TeamColor = BrickColor.new("Really red")

--//Giving the player items 
if player.Team == teamblue then
	local item1 = RepStorage:FindFirstChild("Name of tool")
	local item1clone = item1:Clone()
	item1clone.Parent = player.Backpack
	--//And so on for every item
elseif player.Team = teamred then
	local item1 = RepStorage:FindFirstChild("Name of tool")
	local item1clone = item1:Clone()
	item1clone.Parent = player.Backpack
	--//And so on for every item
end

Now make a function for when the round ends. In it put this.

player.Backpack:remove() --// Removes the items from the players backpack
--//Teleporting the player

local blueteamspawn = game.Workspace.Part --//Change this to the target brick
local redteamspawn = game.Workspace.Part --//Change this part to the target brick

if player.Team == teamblue then
	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		player.Character.HumanoidRootPart.CFrame = blueteamspawn.CFrame + Vector3.new(0,5,0)
	end
elseif player.Team == teamred then
	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		player.Character.HumanoidRootPart.CFrame = redteamspawn.CFrame + 												
		Vector3.new(0,5,0) 
	end
end

I believe this should work for creating the teams and giving the player items, but I don't know how to set teams. Make sure that the giving player items script is in a server script so that it can access the service "ReplicatedStorage" and "Teams".

For setting the teams look at this person's question. https://scriptinghelpers.org/questions/11208/how-can-i-split-up-teams-in-a-script

6 comments

0

Thank you so much i will try it out!

0

Sorry to bother you again but I tried to create a function called function giveweapons and put everything underneath it, but it didn't work. I was also wondering I have a brick called teleport target where the players spawn to do you think you could help me make a teleport target for each team color?

0

DId you put the items in replicated storage?

0

Put the teleportation script at the bottom.

0

Oh ok I will put functions above at the top of the lobby script i made with the teleportation functions underneath. I did put the weapons in replicated storage but it keeps underlining local in blue on line 2 of the giving weapons script. Thanks so much for your help!

0

@fang please look below at my finished script please revise it

Dear Fang please look at this and revise, your work is much appricaited! So the script in whole should look something like this FN Fal is the gun i have in replicated storage

local oldMessage = ""
local minPlayers = 2

function teleportAllPlayers() --What do i have this for if i have teamspawning below in function EndRoundTakeWeps??? please comment below fang
    local target = CFrame.new(workspace.TeleportTarget.Position)
    for i, player in ipairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
        player.Playing.Value = 1
        --add an offset of 5 for each character
    end
end

function message(message)
    if oldMessage ~= message then
        oldMessage = message
        print(message)
    end
end

--Lookout below new code!!!!!

function GiveTeamsWeapons()
--//Services
local RepStorage = game:GetService("ReplicatedStorage")
local teams = game:GetService("Teams")

--//Teams
local teamblue = Instance.new("Team")
teamblue.Name = "TeamBlue"
teamblue.Parent = teams
teamblue.TeamColor = BrickColor.new("Really blue") 
local teamred = Instance.new("Team")
teamred.Name = "TeamRed"
teamred.Parent = teams
teamred.TeamColor = BrickColor.new("Really red")

--//Giving the player items 
if player.Team == teamblue then
    local item1 = RepStorage:FindFirstChild("FN Fal")
    local item1clone = item1:Clone()
    item1clone.Parent = player.Backpack
    --//And so on for every item
elseif player.Team = teamred then
    local item1 = RepStorage:FindFirstChild("FN Fal")
    local item1clone = item1:Clone()
    item1clone.Parent = player.Backpack
    --//And so on for every item
end

--New section for takin thos guns
function EndRoundTakeWeps()
player.Backpack:remove() --// Removes the items from the players backpack

--//Teleporting the player
--Hey PLEASE LOOOOK :3 If this is the team spawn then what about the code above about function teleportALLPlayers would i delete that?
local blueteamspawn = game.Workspace.Part --//Change this to the target brick 
local redteamspawn = game.Workspace.Part --//Change this part to the target brick

if player.Team == teamblue then
    if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        player.Character.HumanoidRootPart.CFrame = blueteamspawn.CFrame + Vector3.new(0,5,0)
    end
elseif player.Team == teamred then
    if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        player.Character.HumanoidRootPart.CFrame = redteamspawn.CFrame +                                                
        Vector3.new(0,5,0) 
    end
end

--ends all the new stuff please

function playersCurrentlyPlaying()
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.Playing.Value == 1 then return true end
    end
    return false
end

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            player.Playing.Value = 0
        end)
    end)

    local playing = Instance.new("IntValue", player)
    playing.Value = 0
    playing.Name = "Playing"
end)


while(true) do
    wait(10)
    if #game.Players:getPlayers() >= minPlayers then
        if playersCurrentlyPlaying() then
            message("Waiting for the current game to end...")
        else
            message("There are enough players for a new game!  Teleporting...")
            wait(4)
            teleportAllPlayers()
        end
    else message("Waiting for more players...") end
end

13 comments

0

@Fangblade16 The two main points I have is the teleportAllPlayers function why do I need that if i have the local blueteamspawn part in function RoundEndTakeWeps. Also you think your could help me make text gui popups for round ending and starting. Thank for all the help!!

0

If you are setting the players teams before you teleport them then in your teleport players function under you for loop replace that part with the teamspawn part, but make sure you set the players teams before teleporting them or it will not work

0

What output error does it give for the giving players items function

0

I am going to test it sometime today but i canot right now do you think you could re-explain the people spawning im confused about it. So in the game i have 3 teams red, blue and spectator. So do i delete the teleportAllPlayers function or what. Sorry on my part

0

When teleporting a player you cant move any body parts using "Position" because it would break the model thus killing the player so you have to change the CFrame property instead. This is the roblox wiki article on teleporting the player:http://wiki.roblox.com/index.php?title=Teleportation

0

And you just need to create another team for the neutral players so that if their on that team they dont get weapons and wont teleport. You could delete the teleportAllPlayers if you wanted to, but u have to make the teleport part of the script run at the time the round starts. If u want to make a gui pop out of the screen then go to the roblox wiki and search up Tweening.

0

Hope this helps.

0

Thank you so much for the clarification, so from what i get I create a neutral team (Spectators) and I Can delete the teleport all players But, I must look at the part of the code that says local redteamspawn = game.Workspace.Part (I would change "Part" to what ever the target brick is for instance Redtele for red correct?

0

yes, sorry for late answer

0

please help me sorry for not understanding i am so new to this here is the team create: https://www.roblox.com/games/678188380/Working-on-a-war-game

0

please accept my roblox freind request

0

turn on team create, invite me, and i will look at the script.

0

I will do that today in about 5 hours (School rn)

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