Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

works for serverside but not client?

--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

1 comment

0

local script is in starterpack

2 answers

✓ Accepted answer

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.

4 comments

0

right ok what should i do to fix it?

0

You should add the tool from the server.

0

im trying to make this script so people cant use exploits to add in btools.

0

urm i think i found a way ty for the info i didnt know that.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.