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.
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â
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â