Help with giving players on a certain team an item

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to give the player specific items based on their team
  2. What is the issue? Include screenshots / videos if possible!
    The issue is it just doesn’t work.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using playeradded, however it just doesn’t work and automatically assumes the player has chosen a team. None of the solutions I found on the developer hub have worked.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Team = game:GetService("Teams")

local Soldier = Team["Soldiers"]
local Wizard = Team["Wizards"]
local WizardPowers = game:GetService("ServerStorage"):WaitForChild("WizardPowers")

game:GetService("Players").PlayerAdded:Connect(function(Player)
	repeat wait() until Player.Team == game.Teams["Wizards"] or game.Teams["Soldiers"]
	print(Player.Name , "has changed teams!")
	local Backpack = Player:WaitForChild("Backpack")
	if Player.Team == Wizard then
		WizardPowers:Clone().Parent = Player.Backpack
		print(Player, "got their powers!")
	elseif Player.Team == Soldier then
		-- Not done yet
	end
end)

This is a script inside of ServerScriptService.
Any help would be greatly appreciated.

Hello im not home so i cant test stuff but ill try to help!

It appears you didn’t do the first if statement correctly!

local Soldier = Team["Soldiers"]
local Wizard = Team["Wizards"]
local WizardPowers = game:GetService("ServerStorage"):WaitForChild("WizardPowers")

game:GetService("Players").PlayerAdded:Connect(function(Player)
	repeat wait() until Player.Team == game.Teams["Wizards"] or game.Teams["Soldiers"]
	print(Player.Name , "has changed teams!")
	local Backpack = Player:WaitForChild("Backpack")
	if Player.Team == game.Teams:FindFirstChild('Wizard') then
		WizardPowers:Clone().Parent = Player.Backpack
		print(Player, "got their powers!")
	elseif Player.Team == Soldier then
		-- Not done yet
	end
end)

Now it seems to give an error,
00:45:59.844 ServerScriptService.GivePowers:1: attempt to index nil with ‘Soldiers’ - Server - GivePowers:1

Try this:

local Soldier = game.Teams:FindFirstChild('Soldiers')
local Wizard = game.Teams:FindFirstChild('Wizard')
local WizardPowers = game:GetService("ServerStorage"):WaitForChild("WizardPowers")

game:GetService("Players").PlayerAdded:Connect(function(Player)
	repeat task.wait() until Player.Team == Soldier or Player.Team == Wizard 
	
	print(Player.Name , "has changed teams!")
	
	local Backpack = Player:WaitForChild("Backpack")
	
	if Player.Team == Wizard then
		WizardPowers:Clone().Parent = Player.Backpack
		print(Player, "got their powers!")
	elseif Player.Team == Soldier then
		-- Not done yet
	end
end)
1 Like

It works! Thanks! I can’t give a short reply though because I recently got the ability to post.

Of course, message me if you need help with anything else!

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