Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
Edited 8 years ago

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

In a LocalScript:

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

In a Script:

1local store_item = game.ReplicatedStorage:WaitForChild("Store_Item")
2function store_item.OnServerInvoke(player, selected_Item)
3    local id = selected_Item:WaitForChild("Item_ID").Value
4    local name = selected_Item:WaitForChild("Item_Name").Value
5    wait(0.5)
6    selected_Item:Destroy()
7    player.PlayerGui.ScreenGui.AddSlot:Invoke(id, name)
8end

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.

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. Async_io 908 — 8y
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. ViciousViperV2 24 — 8y
0
What is "Selected_Item"? User#5423 17 — 8y
0
An ObjectValue. ViciousViperV2 24 — 8y
View all comments (3 more)
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. User#5423 17 — 8y
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? ViciousViperV2 24 — 8y
0
It would be whatever Selected_Item.Value is as that is what you are passing to the remote function. User#5423 17 — 8y

1 answer

Log in to vote
0
Answered by
Radstar1 270 Moderation Voter
8 years ago

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.

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

Answer this question