Im trying to make a little command that adds a string value to a table. However, if a table only has one string value in it, it will just treat it as if it were a string instead of a table with only one value in it. When i try to use table.insert, it will give me an error since it treats it as if it were a string. How can i bypass this?
Could you show us the code? This will help me help you further!
function PlayerOwnsSword(swordName)
local plrSwords = SwordDataStore:GetAsync(plr.UserId)
if plrSwords == nil or table.find(plrSwords, swordName) == nil then
print(plrSwords)
return false
else
return true
end
end
currently, plrSwords is {“LinkedSword”}. If i were to fire this function, it would break where i use table.find. i think this is because roblox would look at {“LinkedSword”} and say "oh, i can just simplify that into “LinkedSword”, and then attempt to use table.find on the “simplified” version.
Lua definitely is not simplifying the table into just a string since those are two completely different types. Can you show the error you’re getting and how you’re saving the player swords into the datstore?
That means you are saving a string to the datastore
That’s weird… I don’t know how you’re getting {"LinkedSword"}
to show up like that in your watched values with a string datatype. This is what I get when using a string vs table
String:
Table:
Edit
Okay I managed to reproduce your output by doing local x = "{\"TestValue\"}"
which I assume isn’t what you’re doing?
In any case I agree with @MrOnlyKemal that you’re somehow saving a string into the datastore. Are you using HttoService:JSONEncode
before saving into the datastore?