Why Gui no go away

Why is my gun Gui not going away?

Hello,
I’m having trouble understanding your problem here. Please go further into detail of what you need.

1 Like

Srry i put the wrong image …

tool.Equipped:Connect(function()
local gungui = script.Parent.GunGui
local plr = game.Players:GetPlayerFromCharacter(tool.Parent)

gungui.Parent = plr.PlayerGui

while wait(0.1) do
	plr.PlayerGui.GunGui.Ammo.AmmoText.Text = ammo.Value.."/"..maxammo.Value
end

end)

tool.Unequipped:Connect(function()
local plr = game:GetService(“Players”):GetPlayerFromCharacter(tool.Parent)
local gungui = plr.PlayerGui.GunGui

gungui.Parent = script.Parent

end)

Thats my code and my gui for my gun doeset go away for some reson

Are there any errors in the output?

Players.uknown_personPRO.Backpack.Assault Rifle.Server:69: attempt to index nil with ‘PlayerGui’

1 Like

Also is this script a localscript?

No its a normal script and it is parented to the gun tool and not the handle or anything else.

You have to do

gungui.Visible = false

and also this is unrelated but instead of using a while loop to update the gui, you can use

ammo:GetPropertyChangedSignal("Value"):Connect(function()
    -- Script to update the text goes here
end)

do this:

tool.Equipped:Connect(function()
local plr = game.Players:GetPlayerFromCharacter(tool.Parent.Parent)
local gungui = plr.PlayerGui.GunGui
gungui.Visible = true

while wait(0.1) do
	plr.PlayerGui.GunGui.Ammo.AmmoText.Text = ammo.Value.."/"..maxammo.Value
end
end)
tool.Unequipped:Connect(function()
local plr = game:GetService(“Players”):GetPlayerFromCharacter(tool.Parent.Parent)
local gungui = plr.PlayerGui.GunGui
gungui.Visible = false
end)

Also what @DAT_BOI875 said i’m just fixing that error.

I want to put the Gui in the gun and I can’t change the visibility becuse the error is saying that it can’t find the PlayerGui and idk why.

The code I posted above should work.

There are now more errors Players.uknown_personPRO.Backpack.Assault Rifle.Server:67: attempt to index nil with ‘PlayerGui’ and GunGui is not a valid member of PlayerGui “Players.uknown_personPRO.PlayerGui”

Make the gun guis’ parent StarterGui. Also can you send me a screenshot of the gun model in explorer.

GunGui is not a valid member of Tool “Workspace.uknown_personPRO.Assault Rifle” and Players.uknown_personPRO.Backpack.Assault Rifle.Server:67: attempt to index nil with ‘PlayerGui’

Oh you can just fire a remote event to a local script and make the Gui go away by just getting the local player. Never mind becuse then it would go to all clients.

I edited the code. Try it now.

Only 1 ERROR now Players.uknown_personPRO.Backpack.Assault Rifle.Server:58: attempt to index nil with ‘PlayerGui’

Ok try now. I hope this works.

Players.uknown_personPRO.Backpack.Assault Rifle.Server:67: attempt to index nil with ‘PlayerGui’