Hello,
I want to create a system that tracks the amount of in-game currency (gems) spent on items. This system should allow people to see the average selling price of a particular item. It needs to work on every server, and whenever an event occurs, the information should be stored in a datastore. The stored value is then retrieved and distributed to all players on each server, including those outside my own server. However, I’m encountering an issue where an error occurs when the event is triggered, displaying
"ServerScriptService.boardscript:164: attempt to index boolean with number "
I hope to get assistance with this problem. I haven’t fully mastered the datastore yet, so I’m unable to come up with a solution on my own. I know how to get an individual value for a player, but I’m unsure how to make it the same for everyone in a table. If you have any questions or need clarification on what I’m doing, feel free to ask.
Here is the code:
local boardimage = ""
local images = {
"rbxassetid://14085555656", --rareimage
"rbxassetid://14716948826", --epicimage
"rbxassetid://14717101543", --legendaryimage
"rbxassetid://14971358701", --exclusiveimage
"rbxassetid://15545891280", --shieldimage
"rbxassetid://15598046397", --vipassimage
"rbxassetid://14763896866", --ttTicketimage
"rbxassetid://15586993560",
"rbxassetid://15587000207",
"rbxassetid://15587004973",
"rbxassetid://15587009892",
"rbxassetid://15587013605",
"rbxassetid://15587017990",
"rbxassetid://15587023725",
"rbxassetid://15587028019",
"rbxassetid://15587031382",
"rbxassetid://15587034799",
"rbxassetid://15587038053",
}
local sellvalueslist = {
["item1"] = 0,
["item2"] = 0,
["item3"] = 0,
["item4"] = 0,
["item5"] = 0,
["item6"] = 0,
["item7"] = 0,
["item8"] = 0,
["item9"] = 0,
["item10"] = 0,
["item11"] = 0,
["item12"] = 0,
}
game.ReplicatedStorage.changevalue.event.OnServerEvent:Connect(function(player, plr, seller, gemprice, rarity, amount)
datastore:SetAsync("sellvalueslist", sellvalueslist)
local oldvalue, errormsg = pcall(function()
return datastore:GetAsync("sellvalueslist")
end)
if oldvalue then
print("OLDVALUE")
for i = 1, #images do
if type(oldvalue) == "table" then
print("IT IS TABLE")
end
print("Checking image", i, boardimage, images[i])
if boardimage == images[i] then
print("Found matching image")
local gemprice3 = gemprice + oldvalue[i]
local gemprice2 = gemprice / 2
print("Gemprice values:", gemprice, gemprice2, gemprice3)
sellvalueslist[i] = gemprice2
print("Updated sellvalueslist", sellvalueslist[i])
break
end
end
datastore:SetAsync("sellvalueslist", sellvalueslist)
end
if errormsg then
warn(errormsg)
sellvalueslist = {
["item1"] = 1,
["item2"] = 1,
["item3"] = 1,
["item4"] = 1,
["item5"] = 1,
["item6"] = 1,
["item7"] = 1,
["item8"] = 1,
["item9"] = 1,
["item10"] = 1,
["item11"] = 1,
["item12"] = 1,
}
datastore:SetAsync("sellvalueslist", sellvalueslist)
end
end)