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 7 years ago
Edited 7 years ago

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.

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

1 answer

Log in to vote
0
Answered by
Radstar1 270 Moderation Voter
7 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.

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

Answer this question