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