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

How do I send an ObjectValue's Value using a RemoteFunction?

So I'm currently trying to send the Value of an ObjectValue using a RemoteFunction.

In a LocalScript:

local store_item = game.ReplicatedStorage:WaitForChild("Store_Item")
local selected_item = script.Parent.Edit:WaitForChild("Selected_Item")
script.Parent.Edit.Inventory.MouseButton1Click:connect(function()
	store_item:InvokeServer(selected_item.Value)
	edit.Visible = false
end)

In a Script:

local store_item = game.ReplicatedStorage:WaitForChild("Store_Item")
function store_item.OnServerInvoke(player, selected_Item)
	local id = selected_Item:WaitForChild("Item_ID").Value
	local name = selected_Item:WaitForChild("Item_Name").Value
	wait(0.5)
	selected_Item:Destroy()
	player.PlayerGui.ScreenGui.AddSlot:Invoke(id, name)
end

When I test in Play Solo, it work's fine. However in a Local Server it gives me the following error.

attempt to index local 'selected_item' (a nil value)

I'm not sure of the issue... any help is appreciated.

7 comments

0

Don't use Play Solo, just a tip. While it takes longer for the Local Server test to load, it is still better than using Play Solo. Perhaps check to see if selecteditem is a thing when running the Server Side thing.

0

Thanks for the quick response. I updated my question post with the Server Side script. I'm still not sure what is going wrong.

0

What is "Selected_Item"?

0

An ObjectValue.

0

If the objects value is only visible / accessible to one side then it will be replaced with nil, ie both sides (client and server) must have access to the object.

0

So should the ObjectValue be located in a specific spot to be able to be accessed from both sides? Currently the ObjectValue is in the PlayerGui... should that be relocated?

0

It would be whatever Selected_Item.Value is as that is what you are passing to the remote function.

1 answer

I believe the reason why it can't index selected_item is because when the server start it hasn't properly loaded. You can fix this by setting a variable for selected_Item the same way you did for store_item.

local store_item = game.ReplicatedStorage:WaitForChild("Store_Item")
local selected_item = (game.ReplicatedStorage:WaitForChild("Selected Item")

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