Hello, im trying to make it where if a tool touches a part it sends a remote event to a server script and it deletes the tool for all players, but instead it deletes the player, any help?
Local Script in Tool
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local InventoryRemotes = ReplicatedStorage:WaitForChild("InventoryRemotes")
local Event = InventoryRemotes:WaitForChild("DeleteAmoung3")
game.Workspace.TouchDoor.Touched:Connect(function(hit)
if hit.Parent:IsA("Tool") and hit.Parent.Name == "amogus3" then
local Players = game:FindFirstChild("Players")
local new = Players:FindFirstChild(hit.Parent.Name)
Event:FireServer(new)
print("Touched")
end
end)
Server Script
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local Folder = ReplicatedStorage:WaitForChild("InventoryRemotes")
local Event = Folder:WaitForChild("DeleteAmoung3")
Event.OnServerEvent:Connect(function(player, Tool)
Tool:Destroy()
end)
That’s why it’s deleting the player, because that’s exactly what you’re sending, not the tool itself. Try actually making it find the tool and delete it from every player.
Also, you should make the server handle the collision for security reasons.
I think the problem is that youre trying to look for the tool in the player, not the player’s character.
Put this in the client script and it should destroy the tool.
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local InventoryRemotes = ReplicatedStorage:WaitForChild("InventoryRemotes")
local Event = InventoryRemotes:WaitForChild("DeleteAmoung3")
game.Workspace.TouchDoor.Touched:Connect(function(hit)
if hit.Parent:IsA("Tool") and hit.Parent.Name == "amogus3" then
local tool = hit.Parent
Event:FireServer(tool)
print("Touched")
end
end)
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local InventoryRemotes = ReplicatedStorage:WaitForChild("InventoryRemotes")
local Event = InventoryRemotes:WaitForChild("DeleteAmoung3")
game.Workspace.TouchDoor.Touched:Connect(function(hit)
if hit.Parent:IsA("Tool") and hit.Parent.Name == "amogus3" then
for _, player in game.Players:GetChildren() do
local tool = player.Backpack.amogus3
Event:FireServer(tool)
end
Event:FireServer(hit.Parent)
end
end)