Tool is returning nil when put through remote event

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Have a player equip a tool when they press a button
  2. What is the issue? Include screenshots / videos if possible!
    the tool is retuning nil when I send it to a remote event
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Apparently I’m not supposed to put player on the client-side of a client to server remote event but IDK maybe that’s the issue
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--Local 
local player = game.Players.LocalPlayer
local BTN = script.Parent
local Frame = script.Parent.Parent

local Rem = game.Workspace.RemoteEvent


BTN.MouseButton1Click:Connect(function()
	local tool = game.Workspace.Plushies[Frame.Name]:Clone()
	print(tool.Name)
	if not player[player.Name .. "Ownerships"][Frame.Name].Value then return end
	local player = game.Players.LocalPlayer
	Rem:FireServer(tool)
	wait()
end)
--Server
local Rem = game.Workspace.RemoteEvent


Rem.OnServerEvent:Connect(function(player, tool)
	local Char = player.Character
	tool.Parent = Char
end)

Error; (on server) ToolChange:6: attempt to index nil with ‘Parent’
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

You’re cloning the tool on the client, and because of FilteringEnabled the tool does not exist on the server. This is why your script is erroring.

What you could do is move the cloning of the tool to the server, and then equip it on the server.

-- LocalScript
local Players = game:GetService("Players") 
local Player = Players.LocalPlayer

local Button = script.Parent
local Frame = script.Parent.Parent

local Remote = workspace.Remote -- You should consider moving this to ReplicatedStorage for organization purposes.

Button.MouseButton1Click:Connect(function()
    if not Player[Player.Name .. "Ownerships"][Frame.Name].Value then return end
    Remote:FireServer("Plushies") -- Here we are passing the name of the tool instead of the object.
end)

-- ServerScript
local Remote = workspace.RemoteEvent

Remote.OnServerEvent:Connect(function(Player, ToolName)
    local Tool = workspace:FindFirstChild(ToolName)

    if Tool ~= nil then
        Tool:Clone().Parent = Player.Character
    end
end)
1 Like