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:
tool= script.Parent
plr=game.Players.LocalPlayer
function onEquipped()
local a =Instance.new("ScreenGui")
a.Parent = plr.PlayerGui
a.Name = "Ammo"
local b = Instance.new ("Frame")
b.Parent = plr.PlayerGui.Ammo
b.Name = "AmmoFrame"
b.Position = UDim2.new(0.7, 0,0.78, 0)
b.Size = UDim2.new(0.3, 2,0.2, 10)
end
function onUnequipped()
if plr.PlayerGui.Ammo ~= nil then
plr.PlayerGui.Ammo:Destroy()
end
end
tool.Unequipped:connect(onUnequipped)
tool.Equipped:connect(onEquipped)
1 comment
There are many, many problems here. I suggest you review your basics.