Help deleting a tool from all players inventory

well i dident know that at the time

so i dont know how to delete it from all players inventory and fixing their inventory Values as well because if i just delete it from their inventorys then it could still say its there lastequippedtool and i have it if u press f it equips lastequippedtool so i need to nil that

Did you even read any of my replies at all?

Otherwise I literally wrote code for nothing

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) and -- check if a player was the one touching itTouch.Parent:FindFirstChild("TestTool") then
		game.ReplicatedStorage.Tools.Touched:FireAllClients("TestTool") -- fire all clients telling them the tool was deleted and telling them what the tools name is 
		for i, v in pairs(game.Players:GetPlayers()) do -- loop through all the players
			if v.Backpack:FindFirstChild("TestTool") then -- check if the player has the tool in their backpack if so then delete it
				v.Backpack.TestTool:Destroy()
			elseif v.Character and v.Character:FindFirstChild("TestTool") then -- check if the tool is in the character if so then delete it
				v.Character.TestTool:Destroy()
			end
		end
	end
end)

bruh i saw that i need help with deleting the values

wouldnt this just go to 1 player like what happened with my script

You’re literally looping through all the players and check if they have the tool in their backpack or character and then destroying it. I don’t see how you can compare it to your script :confused:

you really must not of read the reply huh?

im talking about the one where u LocalPlayer to fix the Values.



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)

this ur script

You fire all clients meaning every client will run that function also change FoundTool.Name to just FoundTool I must’ve missread

then why did this script not work, this script is in everyones Tool and it fires all clients

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
			if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value == FoundTool then
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value = nil
			end
		end
	end
end)

What do you mean? that only triggers when this function runs:

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) and -- check if a player was the one touching itTouch.Parent:FindFirstChild("TestTool") then
		game.ReplicatedStorage.Tools.Touched:FireAllClients("TestTool") -- fire all clients telling them the tool was deleted and telling them what the tools name is 
		for i, v in pairs(game.Players:GetPlayers()) do -- loop through all the players
			if v.Backpack:FindFirstChild("TestTool") then -- check if the player has the tool in their backpack if so then delete it
				v.Backpack.TestTool:Destroy()
			elseif v.Character and v.Character:FindFirstChild("TestTool") then -- check if the tool is in the character if so then delete it
				v.Character.TestTool:Destroy()
			end
		end
	end
end)

i know but when it triggers it only deletes the player who touched the block with the tool

Please read the reply you literally loop through each player and check if they have the tool as said in my previous reply.

this does not fire any clients it runs when FireClient or FireAllClients has been triggered

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
			if game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value == FoundTool then
				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.Equipped.Value = nil				game.Players.LocalPlayer.PlayerGui["Inventory Gui"].Frame.Handler.LastEquippedTool.Value = nil
			end
		end
	end
end)

bro i tried it out and it only deletes it from the 1 guy

Did you put the script in a server script? because any programmer will agree with me and know that this will loop through all the players and check if they have the tool in their backpack or character

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) then -- check if a player was the one touching itTouch.Parent:FindFirstChild("TestTool") then
		game.ReplicatedStorage.Tools.Touched:FireAllClients("TestTool") -- fire all clients telling them the tool was deleted and telling them what the tools name is 
		for i, v in pairs(game.Players:GetPlayers()) do -- loop through all the players
			if v.Backpack:FindFirstChild("TestTool") then -- check if the player has the tool in their backpack if so then delete it
				v.Backpack.TestTool:Destroy()
			elseif v.Character and v.Character:FindFirstChild("TestTool") then -- check if the tool is in the character if so then delete it
				v.Character.TestTool:Destroy()
			end
		end
	end
end)

yeah i did and theres a mistake with the script aswell, the For goes red and idk how to use those so i dont know how to fix

If there is an error it’s most likely a spelling mistake.

script.Parent.Touched:Connect(function(Touch)
	if game.Players:GetPlayerFromCharacter(Touch.Parent) then -- check if a player was the one touching itTouch.Parent:FindFirstChild("TestTool") then
		game.ReplicatedStorage.Tools.Touched:FireAllClients("TestTool") -- fire all clients telling them the tool was deleted and telling them what the tools name is 
		for i, v in pairs(game.Players:GetPlayers()) do -- loop through all the players
			if v.Backpack:FindFirstChild("TestTool") then -- check if the player has the tool in their backpack if so then delete it
				v.Backpack.TestTool:Destroy()
			elseif v.Character and v.Character:FindFirstChild("TestTool") then -- check if the tool is in the character if so then delete it
				v.Character.TestTool:Destroy()
			end
		end
	end
end)
1 Like