local tool = script.Parent local player = game:GetService("Players").LocalPlayer local ammo = 8 local isReload = false local mouse = game.Players.LocalPlayer:GetMouse() local maxAmmo = 8 local ammoGUI = player.PlayerGui:FindFirstChild("Ammo") repeat wait() until ammoGUI local GUI = ammoGUI.Background.Frame repeat wait() until GUI function reload(amount) --function to avoid retyping tool.Name = "Reloading" isReload = true mouse.Icon = "rbxgameasset://Images/GunWaitCursor" wait(2) ammo = amount GUI.Ammo.Text = ammo --tool.Name = "Pistol " .. tostring(ammo) isReload = false mouse.Icon = "rbxgameasset://Images/GunCursor" end tool.Equipped:connect(function(mouse) print("Pistol Equipped") mouse.Icon = "rbxgameasset://Images/GunCursor" GUI.MaxAmmo.Text = maxAmmo game:GetService('UserInputService').InputBegan:connect(function(input, gameprocessed) if input.KeyCode == Enum.KeyCode.R then reload(8) end end) mouse.Button1Down:connect(function() print("Mouse Clicked") if (not isReload) and ammo > 0 then --if Player is not reloading ammo = ammo - 1 GUI.Ammo.Text = ammo --tool.Name = "Pistol " ..tostring(ammo) local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 200) local part, position = workspace:FindPartOnRay(ray, player.Character, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Gray") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = 0 beam.Anchored = true beam.Locked = true beam.CanCollide = false local light = Instance.new("PointLight", beam) light.Range = 15 local distance = (tool.Handle.CFrame.p - position).magnitude beam.Size = Vector3.new(0.3, 0.3, distance) beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, - distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) if part then local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") end repeat wait() until humanoid local att = humanoid.Parent.Name local a = game.Players:FindFirstChild(att) if humanoid then if player.TeamColor ~= a.TeamColor then --anti teamkill start humanoid:TakeDamage(30) end end if ammo == 0 then reload(8) end end else reload(8) end end) tool.Unequipped:connect(function() print("Pistol Unequipped") mouse.Icon = "rbxgameasset://Images/ArrowCursor" end) end)
It keeps saying the variable Ammo GUI is a nil value. It's placed inside of the starterGUI but I want the GUI to be different for every player.