--local script-- script.Parent.ChildAdded:Connect(function(tool) game.ReplicatedStorage.RemoteEvent:FireServer(tool) end)
--server script-- game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, tool) if tool.ClassName == "Tool" then tool:Destroy() end end)
this script destroys the Tool when its added from the server side but if its added from the client side it gives me this error:
ServerScriptService.btololsscript:2: attempt to index local 'tool' (a nil value) Stack Begin Script 'ServerScriptService.btololsscript', Line 2 Stack End
This happens because you cannot transfer instances that are on the client. In this case 'tool' is still on the client and when you send it through the server script, it takes the variable, looks for the instance attached to it and it cannot find it because it is an instance on the client. This also explains why the script works when the tool is added from the server.
You don't need a remote event and you need to put the LocalScript
inside the Tool
. There is the script:
local tool = script.Parent if tool:IsA("Tool") then tool:Destroy() end