I'm trying to replace a value inside a folder that inside a folder inside the player GUI, but it won't change I have a warn() in place for that but it won't warn me. Whats happening. P.s. the script is in a local script inside a folder inside the playergui.
local Player = game.Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local workSpace = game:GetService("Workspace") local Buttons = script.Parent.Parent.MainGui.Buttons local ValuesFolder = script.Parent.Parent.ValuesFolder if Player.Character then if ReplicatedStorage:FindFirstChild(Player.Name.."Country") then local PlayerCountry = ReplicatedStorage:FindFirstChild(Player.Name.."Country") if ValuesFolder.Country.Value == "" then ValuesFolder.Country.Value = PlayerCountry.Value --doesn't work if PlayerCountry.Value == "" then warn("Did not work as intended") --does not print end end end elseif Player.Character == nil then if ReplicatedStorage:FindFirstChild(Player.Name.."Country") then local PlayerCountry = ReplicatedStorage:FindFirstChild(Player.Name.."Country") if ValuesFolder.Country.Value == "" then ValuesFolder.Country.Value = PlayerCountry.Value --doesn't work if PlayerCountry.Value == "" then warn("Did not work as intended") --does not print end end elseif ReplicatedStorage:FindFirstChild(Player.Name.."Country") == nil then local PlayerCountry = ValuesFolder.Country:Clone() PlayerCountry.Name = Player.Name.."Country" PlayerCountry.Parent = ReplicatedStorage.PlayerCountrys --works end end
Made a new variable since in line 36, it specified "PlayerCountries" and in the last code (your code), it was specified the cloned instance to be the parent of "PlayerCountrys" at line 30 (Just fixing a bit of spelling in mine)
I see no errors other than that. It should work just fine even in your script; it just means the script couldn't find the instance and then skips that line of code, then the next executes.
local Player = game.Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local workSpace = game:GetService("Workspace") local Buttons = script.Parent.Parent.MainGui.Buttons local ValuesFolder = script.Parent.Parent.ValuesFolder local PlayerCountries = ReplicatedStorage.PlayerCountries if Player.Character then if PlayerCountries:FindFirstChild(Player.Name.."Country") then local PlayerCountry = PlayerCountries:FindFirstChild(Player.Name.."Country") if ValuesFolder.Country.Value == "" then ValuesFolder.Country.Value = PlayerCountry.Value if PlayerCountry.Value == "" then warn("Did not work as intended") end end elseif not PlayerCountries:FindFirstChild(Player.Name.."Country") then -- Dunno if you need this one, you can delete this elseif statements if you'd like. local PlayerCountry = ValuesFolder.Country:Clone() PlayerCountry.Name = Player.Name.."Country" PlayerCountry.Parent = PlayerCountries end elseif Player.Character == nil then if PlayerCountries:FindFirstChild(Player.Name.."Country") then local PlayerCountry = PlayerCountries:FindFirstChild(Player.Name.."Country") if ValuesFolder.Country.Value == "" then ValuesFolder.Country.Value = PlayerCountry.Value if PlayerCountry.Value == "" then warn("Did not work as intended") end end elseif not PlayerCountries:FindFirstChild(Player.Name.."Country") then local PlayerCountry = ValuesFolder.Country:Clone() PlayerCountry.Name = Player.Name.."Country" PlayerCountry.Parent = PlayerCountries end end
But if you're trying to execute the script after the instance has been added, then you can wrap it up in a function and then call the function. Or you can wrap it up using coroutine.
DevForum: What is Coroutine? by Mysterious_Myth11
DevForum: Coroutines - When and how to use them by ReturnedTrue
Youtube: Advanced Roblox Scripting Tutorial #33 - Coroutine by TheDevKing
Bit of advice: you can use "not" in an if statement
local bool = false local nonExistent = nil local Frame = script.Parent if not bool then print("false") -- Will print else print("this wont print because bool is false") -- Won't print end if nonExistent then print("This won't print because it is nil") else print("This will print because it is nil") end Frame.Visible = not Frame.Visible -- This turns the frame visibility boolean to the opposite boolean, e.g: true to false, false to true
The value isn't set to "" bye default its set to nil so try something like this:
if ValuesFolder.Country.Value == nil then ValuesFolder.Country.Value = PlayerCountry.Value if PlayerCountry.Value == nil then warn("Did not work as intended") end
and if I missed anything else that was set to "" try setting it to nil.