I'm making a shop that uses a module script, here is the script:
local DataStoreService = game:GetService("DataStoreService")
local PlayerAntemDataStore = DataStoreService:GetDataStore("PlayerAnthem")
local OwnedAnthems = DataStoreService:GetDataStore("OwnedPlayerAnthems")
local module = {}
function module:PurchaseAnthem(Player, PlayerAnthemID, Price, AnthemName)
print("Somthing was clicked.")
local CurrentId = PlayerAntemDataStore:GetAsync(Player.UserId)
if (CurrentId ~= PlayerAnthemID) then
if (Player.leaderstats.Coins.Value >= Price) then
Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value - Price
PlayerAntemDataStore:SetAsync(Player.UserId, PlayerAnthemID)
local Anthems = OwnedAnthems:GetAsync(Player.UserId)
print("Got Tabel Async")
local AnthemTabel = {}
print("MadeTabel") --The error is right arround here.
for i, v in pairs(AnthemName) do
table.insert(AnthemTabel, v)
end
print("Edited Tabel")
OwnedAnthems:SetAsync(AnthemTabel)
print("SavedTabel")
local m = Instance.new("Message", Player.PlayerGui)
m.Text = "Purchace Was Succes!"
wait(3)
m:Destroy()
elseif (Player.leaderstats.Coins.Value < Price) then
local m = Instance.new("Message", Player.PlayerGui)
m.Text = "You Do Not Have Enough Coins To Purchace This Player Anthem!"
wait(3)
m:Destroy()
else
local m = Instance.new("Message", Player.PlayerGui)
m.Text = "Unknown Error!"
wait(3)
m:Destroy()
end
else
local m = Instance.new("Message", Player.PlayerGui)
m.Text = "This already is your player anthem!!! (noob)"
wait(3)
m:Destroy()
end
end
return module
The script is not working.
I'm getting an error: invalid argument #1 to 'pairs' (table expected, got string)
I think that that means that it is finding a string instead of a table but overall I am really confused. This is the first time I have used tables and I just figured out how to use a data store. Can someone please help me.
