im trying to make an ammo system for my gun but I get the attempt to index nil error. Can someone help me fix?
you can try to fix it by adding
wait(2) so it can find the gui
Still have the same issue even with a wait
I Have had this issue before try changing the GUI name and see if it works. Thats usually what I do when this happens.
I know this has already been solved but you could also use WaitForChild() when referencing the Gui
Once again, if you read the error closely it’s saying that whatever you are looking for the player gui in is nil, so if
Then this is saying player is nil.
To fix this error, remove the player variable as you are already getting the player passed through the remote event!
-- ammo system start local gui = player.PlayerGui.Info local ammo = script.Parent.Parent.AmmoCounter ammov.Value -= 1 gui.TextLabel.LocalScript.Shot:FireClient(player) -- ammo system end
Yup, now what the next error is saying is you have to pass the player variable to the FireClient statement, check the part of the script I posted above
The problem is you are doing .LocalPlayer in a non local script.