I'm getting an error even though I shouldn't get one

I’m trying to create a GUI which shows the player how much ammo they have left.

I’m using the .Change thing to update a text UI and I get an error for a thing that is a valid member but it says it isn’t.
image

I’ve tried adding .Value but that doesn’t work either and its a LocalScript being used.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

script.Parent.Ammo.Changed:Connect(function(value)
	plr.PlayerGui.PistolGUI.Ammo.AmmoAmount.Text = value
end)

image

All help is appreciated.

It probably didn’t recognize it just yet, this happens a lot to me.

Change your script so that before script.Parent.Ammo.Changed:Connect(function(value) it says

repeat wait() until script.Parent.Ammo
if script.Parent.Ammo then
local ammo = script.Parent.Ammo
end

1 Like

repeat wait() until is a bad practice, and script.Parent.Ammo will never be nil as it’ll just eror as well.
Why are you adding an unnessesary if script.Parent.Ammo then when repeat ... until script.Parent.Ammo already checked it before? local amo = script.Parent.Ammo inside the if scope have no effect as it’ll never be reached as the variable that’s localised can only be accessed inside the scope

It it doesn’t recognise it yet then why not use :WaitForChild?

6 Likes

I did find the easier way by using :WaitForChild() as its much simpler. For example,

   script.Parent:WaitForChild("Configuration").Ammo.Changed:Connect(function(value)
	plr.PlayerGui.PistolGui.Ammo.AmmoAmount.Text = value
end)

And it works perfectly fine! Thank you for both solutions!

1 Like