Delete tool script

Sorry if this title makes absolute so sense to you. I had no idea what to make it. So I made a handheld security scanner tool. When equipped, you can click any player and it shows you their username, acc age, role in group, and their tools. I want to make it so when you hover over the tool name, an x comes up. And when you click the x, it deletes the tool from their inventory, and from the gui. Here is my script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local tool = script.Parent


local Frame = game.Players.LocalPlayer.PlayerGui:WaitForChild('ScannerGUI'):WaitForChild('Frame') --Object path to the GUI frame containing the age and rank textboxes.
local groupID = 4796549 --ID of your group.



tool.Equipped:Connect(function()
	Frame.Visible = true
	Frame.Parent.Backround.Visible = true
end)



tool.Activated:Connect(function()
	for _,Target in pairs(game.Players:GetPlayers()) do
		if Mouse.Target:IsDescendantOf(Target.Character) then
			Frame.AccAge.Text = Target.AccountAge
			Frame.RoleInGroup.Text = Target:GetRoleInGroup(groupID)
			Frame.AccName.Text = Target.Name
			local ToolsInBackpack = Target.Backpack:GetChildren()
			local listStr = ""
			Frame.Tools.Text = ""
			for i,v in pairs(ToolsInBackpack) do
				if v:IsA("Tool") then
					print(v.Name)
					Frame.Tools.Text = Frame.Tools.Text..v.Name.."\n"	
				end
			end
		end	
	end
end)





-- Make sure they can't use the tool while it is not selected.
tool.Unequipped:Connect(function()
	Frame.Visible = false
	Frame.Parent.Backround.Visible = false
end)

Thanks for reading.

1 Like

Is this a local script or script?

You can use a MouseEnter function to detect the mouse over the name. Add a TextButton ‘X’ that can be clicked.

When you click the TextButton, fire a RemoteEvent to the server (with the target and tool’s name) to remove the player’s tool.

Psuedocode:

--// Client
local RemoteEvent = game.ReplicatedStorage.RemoteEvent 

for _, toolName in pairs(toolNameList:GetChildren()) do
	toolName.MouseEnter:Connect(function()
		local remove = Instance.new("TextButton", gui)
		remove.MouseButton1Click:Connect(function()
			RemoteEvent:FireServer(Target, toolName) 
		end
	end)
end


--// Server
local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent.onServerEvent:Connect(function(sender, Target, toolName)
	for _, tool in pairs(Target.Backpack:GetChildren()) do
		tool:Destroy()
	end
end)

local
30 characterssssssssssss

But how do I make it so there is an x button for each tool name?

MouseEnter will only work for a single GuiObject, so if all of the tool’s names are stored in a TextLabel, you wouldn’t be able to get the specific tool name.

I would suggest you use a TextLabel for each tool, and place those TextLabels in a Frame with a UiListLayout for formatting. As in the psudeocode I gave up, loop through all of those TextLabels and create a MouseEnter function for them. The ‘X’ button can be a child of the TextLabel, that goes visible/invisible with the use of MouseEnter and MouseLeave.