So I’ve got this medkit that has a GUI instruction frame that shows up if you equip the tool and disappears if you unequip it. But for some reason, after you use the medkit and the tool disappears from the inventory, the GUI stays. I’ve tried using basic code like script.Parent.Instruct.Frame.BackgroundTransparency = 0, but that doesn’t seem to work. Help?
Medkit script:
local Tool = script.Parent;
enabled = true
function onActivated()
if not enabled then
return
end
enabled = false
Tool.Handle.Sound:Play()
wait(1.5)
Tool.Handle.Transparency = 1
local h = Tool.Parent:FindFirstChild("Humanoid")
if (h ~= nil) then
wait(1)
h.Health = h.Health + 100
end
wait(2.5)
script.Parent:Remove()
end
function onEquipped()
Tool.Handle.Equip:Play()
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
GUI script:
local gui
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct") then -- Your Gui's name.
gui = script.Parent.Instruct:Clone() -- Replace "TestGUI" with your Gui's name.
gui.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
gui:Destroy()
end)
local gui -- this is the problem
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct") then
gui = script.Parent.Instruct:Clone()
gui.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
gui:Destroy()
end)
Take a look at line 1, you’re destroying a variable when you unequip the tool;
You declared gui in the first statement, but you forgot to declare it in the second one.
Try setting it to gui = script.Parent:FindFirstChild("Instruct")
gui = script.Parent:FindFirstChild("Instruct")
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct") then -- Your Gui's name.
gui = script.Parent.Instruct:Clone() -- Replace "TestGUI" with your Gui's name.
gui.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
gui:Destroy()
end)
local gui
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct") then -- Your Gui's name.
gui = script.Parent.Instruct:Clone() -- Replace "TestGUI" with your Gui's name.
gui.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct")
equipped = false
gui:Destroy()
end)
local Tool = script.Parent;
enabled = true
function onActivated()
local gui=game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct")
enabled=not enabled
if enabled==true then
local h = Tool.Parent:FindFirstChild("Humanoid")
Tool.Handle.Sound:Play()
wait(1.5)
Tool.Handle.Transparency = 1
if (h ~= nil) then
wait(1)
h.Health = h.Health + 100
end
wait(2.5)
script.Parent:Destroy()
gui:Destroy()
else
end
end
function onEquipped()
Tool.Handle.Equip:Play()
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
local gui
local equipped = true
script.Parent.Equipped:Connect(function()
equipped = not equipped
if equipped==false then
if not game.Players.LocalPlayer.PlayerGui:FindFirstChild("Instruct") then -- Your Gui's name. -- Replace "TestGUI" with your Gui's name.
gui = script.Parent.Instruct:Clone()
gui.Parent = game.Players.LocalPlayer.PlayerGui
end
else
gui:Destroy()
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
end)
local Tool = script.Parent
player=game.Players.LocalPlayer
enabled = true
equipped = false
instruct = script.Parent.Instruct
function onActivated()
local humanoid = Tool.Parent:FindFirstChild("Humanoid")
enabled=not enabled
if not enabled then
return
end
Tool.Handle.Sound:Play()
wait(1.5)
Tool.Handle.Transparency = 1
if humanoid ~= nil then
wait(1)
humanoid.Health += 100
end
wait(2.5)
Tool:Destroy()
end
script.Parent.Equipped:Connect(function()
equipped = true
if player:FindFirstChild("Instruct")~=nil then
equipped=true
Tool.Handle.Equip:Play()
instruct:Clone()
instruct.Parent = player.PlayerGui
end
end)
script.Parent.Unequipped:Connect(function()
equipped = false
if player.PlayerGui:FindFirstChild("Instruct")~=nil then
player:FindFirstChild("Instruct"):Destroy()
end
end)
script.Parent.Activated:connect(onActivated)