I never had this problem before, does anyone know why this is happening?
First 2 lines of the script (local script in StarterGui)
local button = script.Parent
local inventory = button.Parent:WaitForChild("Inventory")
I never had this problem before, does anyone know why this is happening?
First 2 lines of the script (local script in StarterGui)
local button = script.Parent
local inventory = button.Parent:WaitForChild("Inventory")
I think it’s because the client loads the LocalScript
before the ImageButton
.
Here is what you could do
local button = script.Parent
repeat task.wait()
button = script.Parent
until button
local inventory = button.Parent:WaitForChild("Inventory")
The repeat loop continues until the button variable is no longer nil.
Has it always been like this or is this a new thing?
Sometimes calling objects in the client can throw errors for some reason, but script.Parent
should have no problem at all. Try putting a short delay before anything else to see if loading is the issue. If it’s not, check if anything’s deleting or altering the parent of the script.
fyi gui only loads when your character loads for some reason
Does it work if you parent the LocalScript to the ScreenGui instead of the ImageButton, and replace the code as shown below?
local backpack = script.Parent -- Make sure that the LocalScript's parent is the ScreenGui rather than the ImageButton!
local button = backpack:WaitForChild("ImageButton") -- Might need to change "ImageButton" to the desired button's name, as explained in the edit
local inventory = backpack:WaitForChild("Inventory")
@bettergreen_man I forgot to mention something important: If you wish to use the code above, and the ScreenGui contains many ImageButtons that are using the default name of “ImageButton”, then WaitForChild will return the first ImageButton that happened to load at the time the LocalScript executes, which might not be your desired ImageButton. The easiest way to fix this problem would be to give each ImageButton a different name, and edit the script so that it waits for the correct button
That’s really weird, has it always been like this?
It’s always been like that im pretty sure
Really? I never had this issue before when making the game a few months back, when I came back to test the project, it suddenly outputs a burst of error messages
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.