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

Trying to Access Dictionary with Remote Events? HELP! :(

Asked by 5 years ago

Hello, I'm trying to access this dictionary through a remote event, wondering why it's producing , 'attempt to index local 'item' a nil value


---LOCALSCRIPT---

script.Parent.MouseEnter:Connect(function()

local item = game.ReplicatedStorage.Remotes.FindItem:FireServer(script.Parent.Name)

desc.Text = item[3]

atk.Text = item[1]

def = item[2]

end)


--- SCRIPT---

ITEMS = {

["Basic Sword"] = {1,20,0,"The basic sword, almost too basic...",3,"none"} ,

["Basic Shield"] = {1,0,15,"Well it's a shield... so yea",3,"none"} ,

["The Essence"] = {100,150000,50000,"The essence of the creator, spread through the deepest levels of the dungeon.",500,"Essence"} ,

}

game.ReplicatedStorage.Remotes.FindItem.OnServerEvent:Connect(function(plr,name)

return ITEMS[name]

end)

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Right now, the server script is returning the table to itself. In order for the client to receive the item table, you must use RemoteEvent:FireClient().

Client:

script.Parent.MouseEnter:Connect(function()
game.ReplicatedStorage.Remotes.FindItem:FireServer(script.Parent.Name)
local item
game.ReplicatedStorage.Remotes.FindItem.OnClientEvent:Connect(function(item_)
    item = item_
end)
desc.Text = item[3]
atk.Text = item[1]
def = item[2]

end)

Server:

ITEMS = {
["Basic Sword"] = {1,20,0,"The basic sword, almost too basic…",3,"none"} ,
["Basic Shield"] = {1,0,15,"Well it’s a shield… so yea",3,"none"} ,
["The Essence"] = {100,150000,50000,"The essence of the creator, spread through the deepest levels of the dungeon.",500,"Essence"}
}
game.ReplicatedStorage.Remotes.FindItem.OnServerEvent:Connect(function(plr,name)
    game.ReplicatedStorage.Remotes.FindItem:FireClient(plr,ITEMS[name])
end)

If you're confused about :FireClient or .OnClientEvent, here's the documentation on the wiki.

Ad
Log in to vote
0
Answered by 5 years ago

Instead of using a RemoteEvent, use a RemoteFunction instead and it should start working.

https://developer.roblox.com/api-reference/class/RemoteFunction

Answer this question