script.Parent is nil, even though script absolutely has a parent!

Hi all,

I have a server script which clones a GUI and parents it to PlayerGui.
However, the localscripts in the GUI seem to be starting before the GUI has actually loaded. I have the following code:

task.wait(1)
script.Parent.Visible = true

and am getting the following error:

Players.jackjenningsdev.PlayerGui.EagleGui.LegislationFrame.VotingFrame.VoteYea.LocalScript:2: attempt to index nil with ‘Visible’

Obviously this is confusing because “script.Parent” shouldn’t be nil, especially when the error indicates a path for the script that has a parent!

I have even tried adding task.wait(1) to the very start to delay the localscript’s execution to avoid this error… but no such luck.

Any thoughts?

3 Likes

{E91800A5-0984-4729-BBE5-2C15C1E83504}
are you sure that the parent is a gui and have a Visible propertie? make sure that its Visible and not Enabled

1 Like

Parent is a TextButton named “VoteYea”, as indicated in the error.

If it were a problem with having a valid parent but an invalid property, it would be a different error.

1 Like

if you extended the task.wait() time to 3 or smt would it work?

1 Like

maybe enable the local script after loading in the parent

2 Likes

Where is the GUI located, In replicatedStorage?

1 Like

you can just do

script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
if script.Parent=="yourGui" then
script.Parent.Visible=true
end
end)

Doesn’t work - I presume because the LocalScript doesn’t activate until it has the player as an ancestor to begin with?

…which confuses me because again, if the script has the player as an ancestor, there’s no reason script.Parent should be returning nil

The longer I extend the task.wait the more frequently it works, but it’s not a guarantee, and either way - waiting ~3-5 seconds before the GUI can take input isn’t a viable option.

why not just use serverscript just to make it visible
or
you can do this by disabling localscript by default then
use a serverscript to detect propertychanged signal
if parent is the GUI then enable the localscript

i know that’s a roundabout but it achieves your goal atleast

ohh there is an answer! what did you do

enabled localscripts after parenting the GUI. it’s not as efficient but it works.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.