So I have this shirt giver script, and I have cleaned it up, but its still giving not giving me the shirt even with a value? Any help, no output errors or nothing.
local bunchOfShirts = {
[1] = “rbxassetid://10248083”, --Default Shirt
[2] = “rbxassetid://1178599385”, – Army green
[3] = “rbxassetid://2397305859”, --Guess reckless
[4] = “rbxassetid://885261392”, --Hawaiian shirt
[5] = “rbxassetid://3144003341”, --JackMercando shirt
[6] = “rbxassetid://3152639503”, – Osito Pink Shirt
[7] = “rbxassetid://668772580”, – Red Jacket
[8] = “rbxassetid://554084413”, – Supreme Worldflags
[9] = “rbxassetid://2970602368”, – Tank top
[10] = “rbxassetid://2072675468”, – Tommy hilfiger
[11] = “rbxassetid://2641146107”, – Tour Jacket
[12] = “rbxassetid://604130756” – Yellow puffer
}
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:Connect(function(character)
local d = character:WaitForChild(“Shirt”)
local val = player:WaitForChild(“leaderstats”).Shirt.Value
if val >= 1 then
wait(1)
if val >= #bunchOfShirts then
d.ShirtTemplate = bunchOfShirts[#bunchOfShirts]
else
d.ShirtTemplate = bunchOfShirts[val]
end
end
end)
end)
Mind replying with the solution rather than “I figured it out” so people with a similar problem may see this thread and determine how to resolve their own issue?
The script works perfectly, I just didn’t’ realize changing the leaderstats threw properties didn’t work, and that you had to give yourself the value threw a script.
I was in the middle of writing a response, so I’ve continued it and left it here for your own convenience should you feel like referencing it later. To summarise; I don’t feel like your code functions effectively here and you’re probably not doing something right.
You’re running a pretty unnecessary chunk down there in your PlayerAdded event. Take a different approach. Make it simple.
local Players = game:GetService("Players") -- Use GetService, not dot syntax
local function onCharacterAdded(character)
-- Edge case: player doesn't have shirt, shirt won't get added, infinite yield
local shirt = character:WaitForChild("Shirt")
local configValue = player:WaitForChild("leaderstats").Shirt.Value
-- If shirt exists in bunchOfShirts, give, otherwise select the first one
shirt.ShirtTemplate = bunchOfShirts[configValue] or bunchOfShirts[1]
end
Players.PlayerAdded:Connect(function (player)
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
end)