Gun keeps breaking in Roblox but not in Roblox studio

Hi, I am making a gun in my game and when I test it by resetting multiple times, it still works. However, when I reform the same test with the guns in the actual game, I get this message:

16:43:14 -- GunHolder is not a valid member of ScreenGui "GunGui"

Also, GunHolder is a Gui frame and is a child of ScreenGui.

I’d also used WaitForChild() but it still gives me an error and/or warning. Any help will be appricated! :slight_smile:

1 Like

Could I see more of the script?

Sure!

This is the function where the gun breaks (it’s in a local script):

function Equipped()
	Equipped = true

	GunGUI.Enabled = true
-- This line of code below causes the error
	GunGUI.GunHolder.CurrentAmmo.Text = Ammo
	GunGUI.GunHolder.ReservedAmmo.Text = ReservedAmmo

	CAS:BindAction("Reload", AquireInput, true, Enum.KeyCode.R)
	CAS:SetPosition("Reload", UDim2.new(0.5, 0, 0.05, 0))
	CAS:SetTitle("Reload", "Reload")
	CAS:BindAction("Fire", AquireInput, true, Enum.UserInputType.MouseButton1)
	CAS:SetPosition("Fire", UDim2.new(0.2, 0, 0.1, 0))
	CAS:SetTitle("Fire", "Fire")
end

And, this is some of the references that are the guis:

--LPlr is the local player
local PlayerGUI = LPlr:WaitForChild("PlayerGui")
local GunGUI = PlayerGUI:WaitForChild("GunGui")
GunGUI.GunHolder.CurrentAmmo.Text = Ammo
GunGUI.GunHolder.ReservedAmmo.Text = ReservedAmmo

What are thoughs to values? “Ammo, ReservedAmmo” Are they a value object, Or a value made in the script? (Ammo = 25) (Ammo = script.Ammo)

Or ect

may i see your explorer architecture

Ammo and ReservedAmmo are values made in the script

2024-06-12_175916
Sure! (also the Divider is the decoration and doesn’t do anything)

1 Like

I don’t see any misspelled words or wrongs paths.

What error gets pushed? I don’t see any misspelled words or wrong paths in your code so there might be a chance that the GunHolder gui is disappearing. To test this try printing GunGui:GetDescendents() and see if pops up there.

1 Like

Yes, well it doesn’t show the table or the descendents of the gui as shown in these screenshots:
Screenshot in roblox studio:


Screenshot in roblox:

1 Like