I’m trying to make a player spawn with a different set of clothes each time the player respawns. There are four outfits in total.
local Players = game:GetService("Players")
local shirtA = "https://www.roblox.com/catalog/3261604730/HAWAII-HAWAII-HAWAII-HAWAII-HAWAII-HAWAII-HAWAII"
local shirtB = "https://www.roblox.com/catalog/3121940799/Gray-Wizard-Robes"
local shirtC = "https://www.roblox.com/catalog/766686366/PTA-Shadow-Mercenary"
local shirtD = "https://www.roblox.com/catalog/5033783669/Plaid-Oyster-Suit-Jacket"
local pantsA = "https://www.roblox.com/catalog/3553957176/Black-Slacks"
local pantsB = "https://www.roblox.com/catalog/2005439614/Gray-Robes"
local pantsC = "https://www.roblox.com/catalog/769666482/HB-PTA-Shadow-Mercenary"
local pantsD = "https://www.roblox.com/catalog/5033785373/Plaid-Oyster-Suit-Pants"
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char:WaitForChild("Shirt")
char:WaitForChild("Pants")
local number = math.random(1,4)
if number == 1 then
char.Shirt.ShirtTemplate = shirtA
char.Pants.PantsTemplate = pantsA
elseif number == 2 then
char.Shirt.ShirtTemplate = shirtB
char.Pants.PantsTemplate = pantsB
elseif number == 3 then
char.Shirt.ShirtTemplate = shirtC
char.Pants.PantsTemplate = pantsC
elseif number == 4 then
char.Shirt.ShirtTemplate = shirtD
char.Pants.PantsTemplate = pantsD
end
end)
end)
This code doesn’t generate an error, but I spawn without any clothes on.
I think that it is because you are formatting the ids wrong. Its supposed to be something like this, im not positive on the exact way to format the ids, but I just know that how you did it won’t work.
You run script when the character has not load. Try to use this script:
local Players = game:GetService("Players")
local shirtA = "http://www.roblox.com/asset/?id=3261604730"
local shirtB = "http://www.roblox.com/asset/?id=3121940799"
local shirtC = "http://www.roblox.com/asset/?id=766686366"
local shirtD = "http://www.roblox.com/asset/?id=5033783669"
local pantsA = "http://www.roblox.com/asset/?id=3553957176"
local pantsB = "http://www.roblox.com/asset/?id=2005439614"
local pantsC = "http://www.roblox.com/asset/?id=769666482"
local pantsD = "http://www.roblox.com/asset/?id=5033785373"
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function()
plr.CharacterAdded:Wait()
char:WaitForChild("Shirt")
char:WaitForChild("Pants")
local number = math.random(1,4)
if number == 1 then
char.Shirt.ShirtTemplate = shirtA
char.Pants.PantsTemplate = pantsA
elseif number == 2 then
char.Shirt.ShirtTemplate = shirtB
char.Pants.PantsTemplate = pantsB
elseif number == 3 then
char.Shirt.ShirtTemplate = shirtC
char.Pants.PantsTemplate = pantsC
elseif number == 4 then
char.Shirt.ShirtTemplate = shirtD
char.Pants.PantsTemplate = pantsD
end
end)
end)
end)
So I ended up pulling the template ID from my character by wearing the clothes in game, the script works now. I used a youtube video combined with @55167233gf 's advice to solve this problem.