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)
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?
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)
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)
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)
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
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)
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
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)
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
Tbh I don’t know how to help you unless you show me your explorer and where exactly you put this script