Hello! I’m currently experiencing this issue with tables that i have no idea how to fix! Any help would 100% be appreciated!
I’m trying to check if the “DroppedBy” value is whatever the current string is. (In the lower script) And if it is, add it to a table.
For some reason, it doesn’t add anything if it’s DroppedBy string equals the current string. I’m just trying to filter through every string and see if it equals that. value.
local chanceTable = {}
local weaponModule = require(game.ReplicatedStorage.ModuleStorage.WeaponsModule)
local chanceTable = {}
local stuff = weaponModule.Items
for i = 1, #stuff do
local check = stuff[i].DroppedBy
if check == "Neutral Sans" then
chanceTable[stuff[i].ItemName] = stuff[i].WeaponMaxChance
end
end
local chanceModule = require(game.ReplicatedStorage.ModuleStorage.ChanceModule)
local item = chanceModule.RandomChance(chanceTable)
print(item)
I hope that made sense, if it didn’t, leave a comment. Thank you so much again!
Forgive me if I’m wrong (I’m not sure what you want to do here), but it seems that you are using a '~=' instead of a '==', which checks if the current string is not equal to 'Neutral Sans'. You could trying switching it to '==' to see if that works.
Second, I slightly restructured your code, and this seems to work for me, at least the DroppedBy checking
local chanceTable = {}
local weaponModule = require(game.ReplicatedStorage.ModuleStorage.WeaponsModule)
local chanceModule = require(game.ReplicatedStorage.ModuleStorage.ChanceModule)
local stuff = weaponModule.Items
for _, tbl in ipairs(stuff) do
local check = tbl.DroppedBy
if check == "Neutral Sans" then
chanceTable[tbl.ItemName] = tbl.WeaponMaxChance
print(tbl.ItemName)
end
end
local item = chanceModule.RandomChance(chanceTable)
print(item)
Hm, very odd, says the interval is empty even after adding in your code.
EDIT: I have my tables cram packed due to the amount of items i’m going to add later on
local module = {}
function module.RandomChance(tabl)
local WeightedChances = {}
for Type, Value in next, tabl do
for Loop = 1, Value do
table.insert(WeightedChances, tostring(Type))
end
end
return WeightedChances[math.random(1, #WeightedChances)]
end
return module