So basically, I'm making a GUI that will display how much ammo is left in your gun. I'm using two IntValues inside of the gun, "Ammo" and "MaxAmmo".
When I test to see if the GUI is visible or not, I get the error "Players.JoshGamingHQ1.PlayerGui.AmmoScreen.Frame.TextLabel.LocalScript:1: attempt to index a nil value".
This is the code:
local toolWithAmmo = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Tool").Ammo local toolWithMaxAmmo = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Tool").MaxAmmo local function update() script.Parent.Text = toolWithAmmo.Value.." / "..toolWithMaxAmmo.Value end while true do wait() if toolWithAmmo ~= nil and toolWithMaxAmmo ~= nil then script.Parent.Visible = true update() else script.Parent.Visible = false end end
This script is a Local Script inside of a TextLabel.
(The issue may be obvious and I don't see it, I'm fairly new to Roblox Lua scripting.)