How can I make a button that gives a team their own shirts?

I have tried some codes before never was successful and have checked forums but they didn’t seem to work.

I was wondering how do I script a textbutton that gives the entirity of the teams players the shirt template in that script?

Lets say

  • textbutton
    → Script
    —> shirt template
    When the button is pressed i want it to replace lets say green teams players shirts with that template
3 Likes
local team = nil --replace
local textbutton = script.Parent
local template = textbutton.ShirtTemplateName

textbutton.MouseButton1Click:Connect(function()
	for _,player in ipairs(team:GetPlayers()) do
		local chara = player.Character
		local shirt = chara:FindFirstChild("ShirtTemplate")
		if shirt then
			shirt:Destroy()
			local newShirt = template:Clone()
			newShirt.Parent = chara
                    else
                        local newShirt = template:Clone()
			newShirt.Parent = chara
		end
	end
end)

maybe? this is a guess, may not even work

3 Likes

as you said, didnt work lol
Local script or Script?

local team = game.Teams.Away
local textbutton = script.Parent
local template = textbutton.Shirt

textbutton.MouseButton1Click:Connect(function()
	for _,player in ipairs(team:GetPlayers()) do
		local chara = player.Character
		local shirt = chara:FindFirstChild("ShirtTemplate")
		if shirt then
			shirt:Destroy()
			local newShirt = template:Clone()
			newShirt.Parent = chara
		end
	end
end)
2 Likes

any errors?
i assume just a script
lol

local team = nil --replace
local textbutton = script.Parent
local template = textbutton.ShirtTemplateName

textbutton.MouseButton1Click:Connect(function()
	for _,player in ipairs(team:GetPlayers()) do
		local chara = player.Character
		local shirt = chara:FindFirstChild("Shirt")
		if shirt then
			shirt:Destroy()
			local newShirt = template:Clone()
			newShirt.Parent = chara
		else
			local newShirt = template:Clone()
			newShirt.Parent = chara
		end
	end
end)

i just fixed some things, should work i think (i made it so it will add the shirt if the player doesn’t have a shirt/it can’t find a shirt)

2 Likes

Thanks, I wanted to do this a long time ago as part as a refree menu.

3 Likes

Was wondering, can you modify this for a pants template?

2 Likes

yeah lol, can do that, just check for pants instead of shirt then destroy and clone

1 Like

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