Help deleting a tool from all players inventory

Hello, I’m trying to delete all tools from a players inventory, when a tool touches a block it sends a remote event to the tool that every player has but it only deletes the players who touched the door, I have a custom inventory system but all I need help with is deleting it from all players inventory’s

script.Parent.Touched:Connect(function(Touch)
	if Touch.Parent.Name == "TestTool" then
		local FoundTool = Touch.Parent
		game.ReplicatedStorage.Tools.Touched:FireAllClients(FoundTool)
	end
end)

game.ReplicatedStorage.Tools.Touched.OnClientEvent:Connect(function(FoundTool)
	if FoundTool.Name == script.Parent.Name then
		if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value == FoundTool then
			game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil
			game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Frame.Visible = false
			FoundTool:Destroy()
			if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value == FoundTool then
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil
				FoundTool:Destroy()
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value = nil
			end
		end
	end
end)

1 Like

i think its because im using game.Players.LocalPlayer? how would i access everybodys playergui as well?

1 Like

you shouldn’t remove tools from the client because it will only be deleted from your view, it wont be replicated to the server. Just have a remote like so. or did I misunderstand your request?

RemoteEvent.OnServerEvent:Connect(function(Player)
     Player.Backpack.ClearAllChildren()
end)

If I misunderstood your request then maybe this is correct?

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) and Touch.Parent:FindFirstChild("TestTool") then
		Touch.Parent:FindFirstChild("TestTool"):Destroy()
	end
end)
1 Like

so i need it to delete from Everybodys inventory but i need to access there inventory Gui and if they have the tool thats getting deleted then the value goes nil like this


game.ReplicatedStorage.Tools.Touched.OnClientEvent:Connect(function(FoundTool)
	if FoundTool.Name == script.Parent.Name then
		if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value == FoundTool then
			game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil
			game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Frame.Visible = false
			FoundTool:Destroy()
			if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value == FoundTool then
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil
				FoundTool:Destroy()
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value = nil
			end
		end
	end
end)
1 Like

but the problem is i did it only for the local player so it doesnt go to anyone else, i need to delete it from all players and fix up the values in the inventory script like i did above

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) and Touch.Parent:FindFirstChild("TestTool") then
        game.ReplicatedStorage.Tools.Touched:FireAllClients("TestTool")
		Touch.Parent:FindFirstChild("TestTool"):Destroy()
	end
end)

I don’t understand? Do you want to remove the tool from every players Backpack?

Also I see that in your script you’re trying to compare a string value to an object. Just send the objects name via the event

so im trying to delete it from either there backpack or there character, and if the player has it equipped in the inventory system then the value goes nil

you could just do this in your script

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) and Touch.Parent:FindFirstChild("TestTool") then
		game.ReplicatedStorage.Tools.Touched:FireAllClients("TestTool")
		for i, v in pairs(game.Players:GetPlayers()) do
			if v.Backpack:FindFirstChild("TestTool") then
				v.Backpack.TestTool:Destroy()
			elseif v.Character and v.Character:FindFirstChild("TestTool") then
				v.Character.TestTool:Destroy()
			end
		end
	end
end)

yeah but then i would somehow access there inventory Gui and check if they have it equipped when it gets deleted so i can fix all the values

You can do that on your RemoteEvent.OnClientEvent function ?

because in the inventory Gui i have many values, LastEquippedTool, Selected, Equipped, if it gets deleted from there inventorys the values might still say its the Tool that got deleted, so i need to access the Values

why wouldnt this work?


game.ReplicatedStorage.Tools.Touched.OnClientEvent:Connect(function(FoundTool)
	if script.Parent.Parent.Parent == workspace then -- If Is In Player Not BackPack
		local PlayerName = script.Parent.Parent.Name
		local LocalPlayer = game.Players:WaitForChild(PlayerName)
		local Handler = LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler
		if Handler.Equipped.Value == FoundTool then
			Handler.Equipped.Value = nil
			Handler.Parent.Frame.Visible = false
			FoundTool:Destroy()
			Handler.LastEquippedTool.Value = nil
			if Handler.Selected.Value == FoundTool then -- If there Selecting Tool
				Handler.Parent.Frame.Visible = false
				Handler.Selected.Value = nil
			else 
				local PlayerName1 = script.Parent.Parent.Parent.Name -- if Is In BackPack
				local Handler = PlayerName.PlayerGui["Inventory Gui"].Frame.Handler
				if Handler.Equipped.Value == FoundTool then
					Handler.Equipped.Value = nil
					Handler.Parent.Frame.Visible = false
					FoundTool:Destroy()
					Handler.LastEquippedTool.Value = nil
					if Handler.Selected.Value == FoundTool then -- If there Selecting Tool
						Handler.Parent.Frame.Visible = false
						Handler.Selected.Value = nil
					end
				end
			end
		end
	end
end)

you can just do this, because on the touched event you’re sending the tools name


game.ReplicatedStorage.Tools.Touched.OnClientEvent:Connect(function(FoundTool)
	if FoundTool.Name == script.Parent.Name then
		if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value == FoundTool then
			game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil -- if this is a boolvalue then change it to false
			game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Frame.Visible = false
			if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value == FoundTool then
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil -- if this is a boolvalue then change it to false
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value = nil
			end
		end
	end
end)

i dident use local Player in this one and it still doesnt delete for all players

dont read the – messages in the script i just put idk what i was thinking when i wrote them

There is a lot wrong with this.

First of all: don’t delete tools on the client,
Second you’re getting the LocalPlayer from parents? just do local LocalPlayer = game.Players.LocalPlayer
Third pretty sure you’re comparing a string value with an object and as said in my previous replies you shouldn’t do that :confused:

Tbh I don’t know how to help you unless you show me your explorer and where exactly you put this script

1 Like

no im finding the Players by script.parent Because i thought it would go to all players, me doing Game.Player.LocalPlayer would just do 1 person

What you did will do the exact same thing :confused:

im findind the player in game.players by doing this local PlayerName = script.Parent.Parent.Name