Issue with remote event

ERROR: attempt to index nil with 'Parent'

Client

local Cloned_textbutton = textbutton:Clone()
Loot_to_Inventory_Event:FireServer(Cloned_textbutton)

Server

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	textbutton.Parent = plr:FindFirstChild("Inventory")
end)

I am trying to Clone a textbutton in a local script and send the cloned copy to the server and PARENT it there. Thank you

2 Likes

You can’t replicate something that came from the client to the server. The server would just receive a nil on textbutton, unless the instance actually exist both the server and the client. Since you cloned the text button the server would just receive a nil.

2 Likes

what would be a good way to fix? I need to have a copy of textbutton in a scrollingframe and in the inventory of a player (on the server)

As @MakerDoe has stated, the client cloned the button, and it doesn’t exist on the server. You could do this to fix it:

--client
Loot_to_Inventory_Event:FireServer(textbutton)
--server
Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	textbutton:Clone().Parent = plr:FindFirstChild("Inventory")
end)
1 Like
attempt to index nil with 'Clone'

SERVER

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	textbutton:Clone().Parent = plr:FindFirstChild("Inventory")
end)

CLIENT

textbutton.MouseButton1Down:Connect(function()
			Loot_to_Inventory_Event:FireServer(textbutton)
			textbutton.Parent = PlayerGui:WaitForChild("InventoryScreenGui"):WaitForChild("InventoryFrame").ScrollingFrame
		end)

It would appear that the textbutton is also made on the client. Why are you trying to use the server to put the textbutton into the inventory anyways?

The text button have to exist on the server before you can clone it with the event from the client side. If the instance, or button in this case is made on the client side, the server won’t know what that button is.

I’d say have a button you want to clone stored inside replicatedstorage and you can clone it from there.

The textbutton is a manually made TextButton that I stored inside the ServerStorage

I need to put the textbutton in the players inventory through the server because of Filtering Enabled.

One of them goes to my ScrollingFrame and the other goes to the Players Inventory on the server

image

thats the storage of the text buttons I have
image

Then pass over the name of the textbutton from the client.

--client
Loot_to_Inventory_Event:FireServer(textbutton.Name)
--server
Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	local button = game.ServerStorage.GemsButtons_Folder:FindFirstChild(textbutton)
	
	if button then
		button:Clone().Parent = plr.Inventory
	end
end)

Also, you should probably make this a LOT more secure.

I have tried your idea.

Looks like the server isnt able to find the TextButton inside the ServerStorage

The Server does receive the textbutton.Name
image

	local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
	
	if TextButton then
		TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
	end

The server isnt able to find the gembutton inside the server storage.
image

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	print(textbutton)
	local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
	
	if TextButton then
		TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
	end
end)

thats the whole block of code

Why don’t you just put the TextButton into the ReplicatedStorage? Both server scripts and local scripts have access to that.

Edit: I see you’re trying to store a TextButton into a container called “Inventory”. Why is this the case? A TextButton is a GUI so I really don’t see why the server needs to know when a TextButton is cloned.

To answer the question on why your current attempt using the TestButton.Name isn’t working, the only thing I can think of is the GemsButton_Folder variable isn’t pointing to the correct folder. If that isn’t the problem, then maybe the player doesn’t have a folder called “Inventory” when you’re trying to parent it. Otherwise, I don’t see any reason for it to not work.

I store the ServerStorage so the client cant access it, I put the TextButton inside the player backpack through the server script. The Inventory folder does show inside the player (and the issue is with textbutton, not the parent). The folder reference is right (well I showed the explorer on the image above, so idk)

Well, I’m not exactly sure why it didn’t work, but go ahead and try this:

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	print(textbutton)
	local folder = game.ServerStorage:FindFirstChild("GemsButtons_Folder")
	print(folder.Name, folder)
	
	if folder then
		local button = folder:FindFirstChild(textbutton)
		
		print(button.Name, button)
		if button then
			button:Clone().Parent = plr.Inventory
		end
	end
end)

Still doesnt work, it does print the name of Folder.

Output:

GemsButtons_Folder GemsButtons_Folder

The most stupid thing is that the same script worked in a previous block of code in the same script

Does the TextButton print out when you try to print it (not the name, the actual instance of TextButton after you use FindFirstChild)

OUTPUT
image

SERVER

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	print(textbutton)
	local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
	print(TextButton)
	if TextButton then
		print("Text Button has been cloned")
		TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
	end
end)

Sorry, this isn’t a solution to your problem
However, your remote seems to be very easy to exploit, you should probably sanitize it

An exploiter can fire Loot_to_Inventory_Event with any arbitrary object and send it to their playergui
SO, someone could delete objects or steal items with Loot_to_Inventory_Event:FireServer(workspace.PlsDontDeleteMe)

what would be a good way to prevent that?