Can anyone help me make this script work?

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Gun = script.Parent
local Ammo = Gun.Ammo
local AmmoLabel = Ammo.AmmoText
local AmmoAmount = 8
local MaxAmmo = 8

Gun.Equipped:Connect(function(Ammo)
	local Playergui = Player.PlayerGui
	local AmmoClone = Ammo:Clone()
	AmmoClone.Parent = Playergui
	
	AmmoLabel.Text = tostring(AmmoAmount).."/"..tostring(MaxAmmo)

	Ammo.Changed:Connect(function()
		AmmoLabel.Text = tostring(AmmoAmount).."/"..tostring(MaxAmmo)
	end)
end)

im trying to make a ammo hud for my gun and i just dont know how to make it work

Whats the issue in the code? Does it fail somewhere?

it says the instance ammo cant be cloned and it doesnt show up on the player’s gui even though the ammogui itself is enabled

Ammo is its own Instance with its own set of children, and values. However cloning it doesnt transfer any other references (eg: variables) or changes with it, so AmmoLabel is only going to be applying changes to the Original Gui, instead of the cloned Gui. Any easy fix is to reference whatever element you need from what was cloned rather than the original item, so:

Clone.Element.Text = ThisText;
1 Like