This is driving me absolutely crazy. I have an inventory frame in my InventoryGUI. In studio there are no issues, i can toggle it whenever i want. But in-game its like it doesnt exist. When i check the inventory.Parent it returns nil. When i check if its a descendant of PlayerGui it returns nil. And the thing that annoys me the most is that before those checks i have print check to see if inventory frame has loaded and exists:
repeat task.wait() until player.PlayerGui:FindFirstChild("InventoryGUI")
print("Has inventorygui")
repeat task.wait() until player.PlayerGui.InventoryGUI:FindFirstChild("InventoryFrame")
print("Has inventory frame")
Both those print statements are printed but somehow inventoryFrame.parent is still nil and inventoryFrame doesnt exist in PlayerGui and when i try to toggle it, it doesnt work.
This may be just a detail of your post, and not your actual code, but just in case it’s not, both instance names and properties are case sensitive. inventoryFrame.parent is not the same as InventoryFrame.Parent. If you’re seeing “Has inventory frame” print, then it means the FindFirstChild(“InventoryFrame”) returned a non-nil value. Try printing the return value, and its Parent and see what you get!
yeah i just rushed the post, its written correctly the real script. Ill try printing that, but it still doesnt explain why it works in studio but not in game. Same script same everything but it doesnt work in-game
local player = game:GetService("Players").LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("InventoryGUI")
local frame = gui:WaitForChild("InventoryFrame")
It kind of sounds like you might be getting a reference to your InventoryFrame, which is then becoming invalid because StarterGui is copying to PlayerGui a second time in the live game. This can happen sometimes if your character appearance loads slowly and new body parts trigger a rebuild of your character. You might want to put DescendantAdded and DescendantRemoved event handlers on your LocalPlayer Player object as early as possible and log what’s going on. Perhaps something about your character spawn in the live game is regenerating your PlayerGui. If you uncheck ResetOnSpawn on the ScreenGui container, does the problem still happen?
omg THANK you so much im so stupid. My game manually loads the character so character Autoload is normally disabled but i had enabled it to try something. So the player loaded twice which messed the whole thing up.
Im still confused on why it still worked just fine in studio even though it loaded twice but now that i disabled autoload everything works👍
This is just a race condition due to the character having to replicate from server to client in a live game, whereas in Studio the server and client are both your computer, so it’s instant and usually all happens before your Lua scripts even start running.