I have this script that if you have a value in the pants, it will give you pants, but its not working, any help on this? heres the script.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if player:WaitForChild("leaderstats").Pants.Value == 1 and character:WaitForChild("Pants") then -- "DefaultPants" wait(1) local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.DefaultPants.PantsTemplate end end) end) game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if player:WaitForChild("leaderstats").Pants.Value == 2 and character:WaitForChild("Pants") then -- "Dark Grey Jeans With White Shoes" wait(1) local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.DarkGreyPants.PantsTemplate end end) end)
Connecting functions to a PlayerAdded event twice in a single script makes me uncomfortable lol
You can take a look and then try to learn if you think it solves your problem. Cheers!
--Go to StarterPlayer and insert a model. Then add Pants as a child, then name it "Pants". --This one goes to ServerScriptService. local libraryOfPants = { DefaultPants = "rbxassetid://279269808", DarkGreyJeans = "rbxassetid://1346697294" } -- a bunch of pants game.Players.PlayerAdded:connect(function(player) --You might have already created one, so you may not need this. --Unless that, you may want to leave it here! local leaderboard = Instance.new("Folder") leaderboard.Name = "leaderstats" local val = Instance.new("IntValue", leaderboard) val.Name = "Pants" leaderboard.Parent = player val.Value = 2 --For testing purposes oof player.CharacterAdded:Connect(function(character) if player:WaitForChild("leaderstats").Pants.Value == 1 then -- "DefaultPants" wait(1) local d = character:WaitForChild("Pants") d.PantsTemplate = libraryOfPants.DefaultPants --The pants may load slowly depends on your connection. elseif player:WaitForChild("leaderstats").Pants.Value == 2 then -- "Dark Grey Jeans With White Shoes" wait(1) local d = character:WaitForChild("Pants") d.PantsTemplate = libraryOfPants.DarkGreyJeans --beautiful end end) end)
Also, I think the problem might be that the player doesn't have the preset pants in their character's Pants instance.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if player:WaitForChild("leaderstats").Pants.Value == 1 and character:WaitForChild("Pants") then -- "DefaultPants" wait(1) local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.DefaultPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 2 and character:WaitForChild("Pants") then -- "Dark Grey Jeans With White Shoes" wait(1) local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.DarkGreyPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 3 and character:WaitForChild("Pants") then -- "Khaki Pants With Black Shoes" local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.KhakiPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 4 and character:WaitForChild("Pants") then -- "Light Blue Pink Shoes" local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.LightBluePinkShoes.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 5 and character:WaitForChild("Pants") then -- "Light Blue Jeans With White Shoes" local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.LightBlueWhiteShoePants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 6 and character:WaitForChild("Pants") then -- "True Religion Jeans & Jordans" local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.TrueReligionPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 7 and character:WaitForChild("Pants") then -- "My Butters" local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.MyButters.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 8 and character:WaitForChild("Pants") then -- Ripped Balmains & Retro 13's local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.RippedPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 9 and character:WaitForChild("Pants") then -- Ripped Balmains & Retro 13's local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.DarkBluePants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 10 and character:WaitForChild("Pants") then -- Ripped Balmains & Retro 13's local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.BottomPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 11 and character:WaitForChild("Pants") then -- Ripped Balmains & Retro 13's local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.BlueJeanBootPants.PantsTemplate elseif player:WaitForChild("leaderstats").Pants.Value == 12 and character:WaitForChild("Pants") then -- Ripped Balmains & Retro 13's local d = character:FindFirstChild("Pants") d.PantsTemplate = script.Pants.BlackJeanBrownPants.PantsTemplate end end) end)
This should work, but I pretty much gave up on indentation because of how much code there was to fix.
The problem was that you have several player added/character added events and not having all of the code in one central event. I'm still puzzled on why you would do this but oh well.