Your code is wrong. Your function is not complete and the way you want to make the GUI is wrong. Also you don't have an unequip function and a code that will remove the GUI when a player unequips the weapon.
I corrected your code, I removed mistakes, I completed the function and I added an unequip function wtih 2 simple lines of code that remove the GUI when the player unequips the weapon.
To make the script work, you would have to paste the code that I wrote for you in a script (not a local script) and have a Handle for your weapon.
Script:
02 | plr = game.Players.LocalPlayer |
04 | local a = Instance.new( "ScreenGui" ) |
05 | a.Parent = plr.PlayerGui |
07 | local b = Instance.new ( "Frame" ) |
08 | b.Parent = plr.PlayerGui.Ammo |
10 | b.Position = UDim 2. new( 0.7 , 0 , 0.78 , 0 ) |
11 | b.Size = UDim 2. new( 0.3 , 2 , 0.2 , 10 ) |
14 | function onUnequipped() |
15 | if plr.PlayerGui.Ammo ~ = nil then |
16 | plr.PlayerGui.Ammo:Destroy() |
19 | tool.Unequipped:connect(onUnequipped) |
20 | tool.Equipped:connect(onEquipped) |