I have this script that turns on the GUI inside of the tool. Whenever the player drops the tool, the GUI doesn’t destroy itself. Is there a line of code that I can add that detects when the tool is dropped and that means I can turn off or destroy the GUI
script.Parent.Equipped:Connect(function()
local playerName = script.Parent.Parent.Name
local player = game.Players:FindFirstChild(playerName)
local gui = script.Parent.HUD
gui.Parent = player.PlayerGui
end)
script.Parent.Unequipped:Connect(function()
local player = script.Parent.Parent.Parent
local gui = player.PlayerGui.HUD
gui.Parent = script.Parent
end)
workspace.ChildAdded:Connect(function(item)
if item:IsA("Tool") then
if not item.Parent:IsA("Model") and game.Players:GetPlayerFromCharacter(item.Parent) then
-- Do something fun!
end
end
end
Please mark this as a solution if it helps, thanks.
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local character = player.Character or player.CharacterAdded:Wait()
local tool = script.Parent
local hud = tool:WaitForChild("HUD")
tool.Equipped:Connect(function()
hud.Parent = playerGui
end)
tool.Unequipped:Connect(function()
hud.Parent = tool
end)
character.ChildRemoved:Connect(function(child)
if child == tool then
hud.Parent = tool
end
end)
Assuming this is a local script.
You can also disable the tool’s CanBeDropped property.