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

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

end)

Server:

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

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

Ad
Log in to vote
0
Answered by 6 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