Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

works for serverside but not client?

Asked by
MHaven1 159
5 years ago
Edited 5 years ago
--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
0
local script is in starterpack MHaven1 159 — 5y

2 answers

Log in to vote
1
Answered by
INOOBE_YT 387 Moderation Voter
5 years ago

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.

0
right ok what should i do to fix it? MHaven1 159 — 5y
0
You should add the tool from the server. INOOBE_YT 387 — 5y
0
im trying to make this script so people cant use exploits to add in btools. MHaven1 159 — 5y
0
urm i think i found a way ty for the info i didnt know that. MHaven1 159 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question