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

When I do ;host I get my team but for the tools Nothing happens???

Hello, when I do ;host It ranks me Host. But when I try to get the tools for it by reseting nothing happens.

Code:

function teamFromColor (color)
for _,t in pairs(game:GetService("Teams"):GetChildren()) do
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 answer

Assuming the Ancestry for the tools are "Server Storage" --> Model (Named after the Team) --> Tools, you can simply all of this down.

Using the Player.CharacterAdded event, you won't need the "onChanged" event

After this, we can simply make a table of the teams and check if the player is on the team and give them a corresponding tool

Server Script

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Character)
		for a, team in pairs(game:GetService("Teams"):GetTeams()) do
			if team == plr.Team then
				for b, tool in pairs(game:GetService("ServerStorage"):WaitForChild(team.Name):GetChildren()) do
					tool:Clone().Parent = plr.Backpack
				end
			end
		end
	end)
end)

For this to work, make sure you have a model containing the tools for that team under Server Storage named the exact same way as the team itself is.

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