The links are the pictures incase anyone doesnt know.
Okay so this is a complex script so I am going to try to fill you in as much as possible.
I have a class selection script, the way it works is when the main script teleports the player to the class selection area, it then enables a class selection GUI.
https://imgur.com/utdudfn
After it enables the GUI a screen pops up that prompts you to pick your class.
https://imgur.com/vYWRWIN
Now this is where the scripts come in, so you can pick the Santa class perfectly fine, it works great infact. But I used the same strategy to let you pick the snowman class and it failed.
Before I show you the scripts here is some more information about the way they work because its a little confusing.
When you pick your class it also changes the way your character looks meaning different clothing, well when you died it removed your clothing so I solved this by creating the script ill show you soon. When you join the game it creates a String value under server storage, this string value remembers your userId. Later on when you pick your class it sets the value of the string value to what ever class you picked. In this situation it would be either "Santa" or "Snowman". Once it does that it waits for you to die and if you do die, it checks what the value of the string was and if it was snowman or santa, it runs the function again just like you were pressing the class select button again.
Heres the scripts, the first one ill show you is the local script. It looks for Frames and the 2 frames have specific names which ever frame you picked is what class you are.
https://imgur.com/bZFFe1l
So here is the local script.
local changeOutfit = game.ReplicatedStorage.ChangeOutfit for _, frame in pairs(script.Parent:GetChildren()) do if frame:IsA("Frame") then frame.Button.MouseButton1Click:connect(function() changeOutfit:InvokeServer(frame.Name) script.Parent:Destroy() end) end end
And here is the serverside script.
local classHandler = game.ServerStorage.ClassHandler local clothingStorage = game.Workspace.ClothingStorage local changeOutfit = game.ReplicatedStorage.ChangeOutfit function setClass(class, player) local char = player.Character -- Makes your class Santa if class == "Santa" then local folder = clothingStorage.Santa if char:findFirstChild("Shirt") then char.Shirt:Destroy() elseif char:findFirstChild("Pants") then char.Shirt:Destroy() elseif char:FindFirstChild("Accessory") then char.Accessory:Destroy() end folder.Shirt:clone().Parent = char folder.Pants:clone().Parent = char local weapon = game.ReplicatedStorage.Thompson weapon:clone().Parent = player.Backpack -- Makes your class Snowman elseif class == "Snowman" then local folder = clothingStorage.Snowman if char:findFirstChild("Shirt") then char.Shirt:Destroy() elseif char:findFirstChild("Pants") then char.Shirt:Destroy() elseif char:FindFirstChild("Accessory") then char.Accessory:Destroy() end folder.Shirt:clone().Parent = char folder.Pants:clone().Parent = char local weapon = game.ReplicatedStorage.PumpShotgun weapon:clone().Parent = player.Backpack end end function changeOutfit.OnServerInvoke(player, class) local value = classHandler:findFirstChild("Player_"..player.UserId) if value then value.Value = class end setClass(class, player) end game.Players.PlayerAdded:connect(function(player) -- This stores which class the player has currently selected local value = Instance.new("StringValue") value.Name = "Player_"..player.UserId value.Parent = classHandler player.CharacterAdded:connect(function(char) setClass(value.Value, player) end) end) game.Players.PlayerRemoving:connect(function(player) local value = classHandler:findFirstChild("Player_"..player.UserId) if value then value:Destroy() end end)
The problem is it wont let me select the snowman class but it lets me select the santa class. And I have no clue why.
This is my last bug in my entire game, and if I could just fix this one last bug I would be so happy. Hopefully someone on this site can help me out :)
Thank you so so much for your time and hopefully I get an answer to this problem
I know I told you how to fix it, but I'll post it here again for anyone else with this issue. At the top of your local script, add a
repeat wait() until #script.Parent:GetChildren()==3 -- Change the 3 to whatever the number is
You need this because GUIs load very quickly, but in order. That means that once your local script has been loaded, does not mean all the other gui elements have been loaded yet. That is why we always use :WaitForChild() for gui objects. However, if you're looping through the children without using WaitForChild, you should have a repeat wait at the top, or at least some sort of wait()