Where can i put this script?

hello developers, so i have this script which gives items in which teams there on:

if player.Team == teams.Blue then
	redlaser:Clone().Parent = player:WaitForChild("Backpack")
	redlaser:Clone().Parent = player:WaitForChild("StarterGear")
	if player.Team == teams.Red then
		bluelaser:Clone().Parent = player:WaitForChild("Backpack")
		bluelaser:Clone().Parent = player:WaitForChild("StarterGear")
	end
end	

so i wanna put in this script which is a deathmatch system:

local Time = game.ReplicatedStorage.Time
local BlueKill = game.ReplicatedStorage.BlueKill
local RedKill = game.ReplicatedStorage.RedKill
local Status = game.ReplicatedStorage.Status
local Teams = game:GetService("Teams")
local redlaser = game.ReplicatedStorage.RedLaserGun
local bluelaser = game.ReplicatedStorage.BlueLaserGun

local BlueTeam = 0
local RedTeam = 0

function TimeWait(TimeToWait)
	Time.Value = TimeToWait
	
	repeat
		wait(1)
		Time.Value -= 1
	until Time.Value < 1
end

game.Players.PlayerAdded:Connect(function(player)
	if Status.Value == "Round in progress" then
		if BlueTeam < RedTeam then
			BlueTeam += 1
			player.Team = Teams.Blue
			player.TeamColor = Teams.Blue.TeamColor
		elseif RedTeam < BlueTeam then
			RedTeam += 1
			player.Team = Teams.Red
			player.TeamColor = Teams.Red.TeamColor
		end
		
		wait(1)
		player:LoadCharacter()
	end
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			if character.Humanoid:FindFirstChild("creator") then
				local killer = character.Humanoid:FindFirstChild("creator").Value
				
				if killer.TeamColor == Teams.Blue.TeamColor then
					BlueKill.Value += 1
				else
					RedKill.Value += 1
				end
			end
		end)
	end)
end)

while true do
	BlueTeam = 0
	RedTeam = 0
	RedKill.Value = 0
	BlueKill.Value = 0
	
	for _,v in pairs(game.Players:GetChildren()) do
		v.Team = Teams.Neutral
		v.TeamColor = Teams.Neutral.TeamColor
	end
	
	wait(1)
	
	for _,v in pairs(game.Players:GetChildren()) do
		v:LoadCharacter()
	end
	
	Status.Value = "Intermission"
	TimeWait(20)
	
	if #game.Players:GetChildren() < 2 then 
		Status.Value = "Need More Players" 
		TimeWait(5)
	else
		Status.Value = "Round in progress"

		for _,v in pairs(game.Players:GetChildren()) do
			if BlueTeam <= RedTeam then
				BlueTeam += 1
				v.Team = Teams.Blue
				v.TeamColor = Teams.Blue.TeamColor

			elseif RedTeam < BlueTeam then
				RedTeam += 1
				v.Team = Teams.Red
				v.TeamColor = Teams.Red.TeamColor

			end
		end
		
		wait(1)
		
		for _,v in pairs(game.Players:GetChildren()) do
			v:LoadCharacter()
		end
		
		TimeWait(20)

		for _,v in pairs(game.Players:GetChildren()) do
			v.Team = Teams.Neutral
			v.TeamColor = Teams.Neutral.TeamColor
		end
		
		wait(1)
		
		for _,v in pairs(game.Players:GetChildren()) do
			v:LoadCharacter()
		end

		if BlueKill.Value > RedKill.Value then
			Status.Value = "Blue Win!"

		elseif RedKill.Value > BlueKill.Value then
			Status.Value = "Red Win!"

		else
			Status.Value = "Tie!"
		end

		TimeWait(5)
	end
end

i try put it on the below game.Players.PlayerAdded but it doesnt work any solution?

1 Like

do all the scripts work and function correctly?

yes all script running correctly

You would have to edit the first script to Teams instead of teams

ok i would do that but first where can i implement this script to deathmatch system script

image

it looks like a server script, so just put it in serverscriptservice

yo man it doesnt work when i wait the intermission to spawn me on the map the gun doesnt clone on my starterpack:

local Time = game.ReplicatedStorage.Time
local BlueKill = game.ReplicatedStorage.BlueKill
local RedKill = game.ReplicatedStorage.RedKill
local Status = game.ReplicatedStorage.Status
local teams = game:GetService("Teams")
local redlaser = game.ReplicatedStorage.RedLaserGun
local bluelaser = game.ReplicatedStorage.BlueLaserGun

local BlueTeam = 0
local RedTeam = 0

function TimeWait(TimeToWait)
	Time.Value = TimeToWait
	
	repeat
		wait(1)
		Time.Value -= 1
	until Time.Value < 1
end

game.Players.PlayerAdded:Connect(function(player)
	if Status.Value == "Round in progress" then
		if BlueTeam < RedTeam then
			BlueTeam += 1
			player.Team = teams.Blue
			player.TeamColor = teams.Blue.TeamColor
		elseif RedTeam < BlueTeam then
			RedTeam += 1
			player.Team = teams.Red
			player.TeamColor = teams.Red.TeamColor
		end
		
		if player.Team == teams.Blue then
			redlaser:Clone().Parent = player:WaitForChild("Backpack")
			redlaser:Clone().Parent = player:WaitForChild("StarterGear")
			if player.Team == teams.Red then
				bluelaser:Clone().Parent = player:WaitForChild("Backpack")
				bluelaser:Clone().Parent = player:WaitForChild("StarterGear")
			end
		end
		wait(1)
		player:LoadCharacter()
	end
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			if character.Humanoid:FindFirstChild("creator") then
				local killer = character.Humanoid:FindFirstChild("creator").Value
				
				if killer.TeamColor == teams.Blue.TeamColor then
					BlueKill.Value += 1
				else
					RedKill.Value += 1
				end
			end
		end)
	end)
end)

while true do
	BlueTeam = 0
	RedTeam = 0
	RedKill.Value = 0
	BlueKill.Value = 0
	
	for _,v in pairs(game.Players:GetChildren()) do
		v.Team = teams.Neutral
		v.TeamColor = teams.Neutral.TeamColor
	end
	
	wait(1)
	
	for _,v in pairs(game.Players:GetChildren()) do
		v:LoadCharacter()
	end
	
	Status.Value = "Intermission"
	TimeWait(20)
	
	if #game.Players:GetChildren() < 2 then 
		Status.Value = "Need More Players" 
		TimeWait(5)
	else
		Status.Value = "Round in progress"

		for _,v in pairs(game.Players:GetChildren()) do
			if BlueTeam <= RedTeam then
				BlueTeam += 1
				v.Team = teams.Blue
				v.TeamColor = teams.Blue.TeamColor

			elseif RedTeam < BlueTeam then
				RedTeam += 1
				v.Team = teams.Red
				v.TeamColor = teams.Red.TeamColor

			end
		end
		
		wait(1)
		
		for _,v in pairs(game.Players:GetChildren()) do
			v:LoadCharacter()
		end
		
		TimeWait(20)

		for _,v in pairs(game.Players:GetChildren()) do
			v.Team = teams.Neutral
			v.TeamColor = teams.Neutral.TeamColor
		end
		
		wait(1)
		
		for _,v in pairs(game.Players:GetChildren()) do
			v:LoadCharacter()
		end

		if BlueKill.Value > RedKill.Value then
			Status.Value = "Blue Win!"

		elseif RedKill.Value > BlueKill.Value then
			Status.Value = "Red Win!"

		else
			Status.Value = "Tie!"
		end

		TimeWait(5)
	end
end

pls take a look in the script what i did wrong.

idk, i don’t have time to analyze your entire script but think about what its doing… from a quick glance it seems like when players join (playeradded) if the status is 'Round in progress" they should get the items, if not then nothing will happen for them ever.

I think you need another function that gives team players items when the round starts also.(not just new player joins)

Hello! There are two main problems.

  1. There is wrong conditional logic, how you are checking the team and the gun to clone, is incorrect.

  2. The guns may not be spawning due to the character not being fully loaded.

Here’s what i changed:

local Time = game.ReplicatedStorage.Time
local BlueKill = game.ReplicatedStorage.BlueKill
local RedKill = game.ReplicatedStorage.RedKill
local Status = game.ReplicatedStorage.Status
local teams = game:GetService("Teams")
local redlaser = game.ReplicatedStorage.RedLaserGun
local bluelaser = game.ReplicatedStorage.BlueLaserGun

local BlueTeam = 0
local RedTeam = 0

function TimeWait(TimeToWait)
	Time.Value = TimeToWait
	
	repeat
		wait(1)
		Time.Value -= 1
	until Time.Value < 1
end

game.Players.PlayerAdded:Connect(function(player)
	if Status.Value == "Round in progress" then
		if BlueTeam < RedTeam then
			BlueTeam += 1
			player.Team = teams.Blue
			player.TeamColor = teams.Blue.TeamColor
		elseif RedTeam < BlueTeam then
			RedTeam += 1
			player.Team = teams.Red
			player.TeamColor = teams.Red.TeamColor
		end
		
		-- Wait for the player's character to load before giving them the gun
		player.CharacterAdded:Wait()
		
		if player.Team == teams.Blue then
			bluelaser:Clone().Parent = player:WaitForChild("Backpack")
			bluelaser:Clone().Parent = player:WaitForChild("StarterGear")
		elseif player.Team == teams.Red then
			redlaser:Clone().Parent = player:WaitForChild("Backpack")
			redlaser:Clone().Parent = player:WaitForChild("StarterGear")
		end
		
		player:LoadCharacter()
	end
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			if character.Humanoid:FindFirstChild("creator") then
				local killer = character.Humanoid:FindFirstChild("creator").Value
				
				if killer.TeamColor == teams.Blue.TeamColor then
					BlueKill.Value += 1
				else
					RedKill.Value += 1
				end
			end
		end)
	end)
end)

while true do
	BlueTeam = 0
	RedTeam = 0
	RedKill.Value = 0
	BlueKill.Value = 0
	
	for _,v in pairs(game.Players:GetChildren()) do
		v.Team = teams.Neutral
		v.TeamColor = teams.Neutral.TeamColor
	end
	
	wait(1)
	
	for _,v in pairs(game.Players:GetChildren()) do
		v:LoadCharacter()
	end
	
	Status.Value = "Intermission"
	TimeWait(20)
	
	if #game.Players:GetChildren() < 2 then 
		Status.Value = "Need More Players" 
		TimeWait(5)
	else
		Status.Value = "Round in progress"

		for _,v in pairs(game.Players:GetChildren()) do
			if BlueTeam <= RedTeam then
				BlueTeam += 1
				v.Team = teams.Blue
				v.TeamColor = teams.Blue.TeamColor

			elseif RedTeam < BlueTeam then
				RedTeam += 1
				v.Team = teams.Red
				v.TeamColor = teams.Red.TeamColor

			end
		end
		
		wait(1)
		
		for _,v in pairs(game.Players:GetChildren()) do
			v:LoadCharacter()
		end
		
		TimeWait(20)

		for _,v in pairs(game.Players:GetChildren()) do
			v.Team = teams.Neutral
			v.TeamColor = teams.Neutral.TeamColor
		end
		
		wait(1)
		
		for _,v in pairs(game.Players:GetChildren()) do
			v:LoadCharacter()
		end

		if BlueKill.Value > RedKill.Value then
			Status.Value = "Blue Win!"

		elseif RedKill.Value > BlueKill.Value then
			Status.Value = "Red Win!"

		else
			Status.Value = "Tie!"
		end

		TimeWait(5)
	end
end

ohh thats the problem gonna try it then.

umm hey badnews it doesnt work let me take a video:

robloxapp-20240612-2056109.wmv (1.1 MB)

the character fully loaded correctly but the item doesnt clone.

Clone the item when the player’s character loads and check their teams when they do, the problem I see is that you’re trying to clone the items when the player is added and since the teams are set around 60 seconds later the items will only clone once, but it detects the player is neither in red or blue team, the thing is when a player reloads or resets their tool will disappear unless it in starter pack or is added in with a script using criteria such as team specific tools. Here is what I would change in character added function:

player.CharacterAdded:Connect(function(character)
        -- Edit Below
        if player.Team == teams.Blue then
			bluelaser:Clone().Parent = player:WaitForChild("Backpack")
			bluelaser:Clone().Parent = player:WaitForChild("StarterGear")
		elseif player.Team == teams.Red then
			redlaser:Clone().Parent = player:WaitForChild("Backpack")
			redlaser:Clone().Parent = player:WaitForChild("StarterGear")
		end
        -- ^ Edit Above ^
		character.Humanoid.Died:Connect(function()
			if character.Humanoid:FindFirstChild("creator") then
				local killer = character.Humanoid:FindFirstChild("creator").Value
				
				if killer.TeamColor == teams.Blue.TeamColor then
					BlueKill.Value += 1
				else
					RedKill.Value += 1
				end
			end
		end)
	end)

The player added function is fired when the player connects to the game/server not when the character is loaded, reloaded, or reset. This is detectable through character added, so when you are reloading the character when the game starts this function will fire and give the tools to the players, and also will work when the player respawns.
Please let me know if this helped/worked.

this is the script would be right just checking:

	player.CharacterAdded:Connect(function(character)
		if player.Team == teams.Blue then
			bluelaser:Clone().Parent = player:WaitForChild("Backpack")
			bluelaser:Clone().Parent = player:WaitForChild("StarterGear")
		elseif player.Team == teams.Red then
			redlaser:Clone().Parent = player:WaitForChild("Backpack")
			redlaser:Clone().Parent = player:WaitForChild("StarterGear")
		character.Humanoid.Died:Connect(function()
			if character.Humanoid:FindFirstChild("creator") then
				local killer = character.Humanoid:FindFirstChild("creator").Value
				if killer.TeamColor == teams.Blue.TeamColor then
					BlueKill.Value += 1
				else
					RedKill.Value += 1
				end
			end
		end)
	end
end)
1 Like

it worked but it clones two same gun in player’s starterpack but after round in progress end the guns stayed in player’s starterpack before he spawns in the intermission.

hey guys i found the solution i made the new script and create this function:

function teamFromColor(color) 
	for _,t in pairs(game:GetService("Teams"):GetChildren()) do 
		if t.TeamColor == color then return t end 
	end 
	return nil 
end 

function onSpawned(plr) 
	local tools = teamFromColor(plr.TeamColor):GetChildren() 
	for _,c in pairs(tools) do 
		c:Clone().Parent = plr.Backpack 
	end 
end 

function onChanged(prop,plr) 
	if prop == "Character" then 
		onSpawned(plr) 
	end 
end 

function onAdded(plr) 
	plr.Changed:connect(function(prop) 
		onChanged(prop,plr) 
	end) 
end 

game.Players.PlayerAdded:connect(onAdded)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.