What do you want to achieve?
I want to make it so it saves the player’s data in the dictionary. ([playername] = score)
What is the issue?
The data is printing ([1] = “WoofWoofWatermelonYT”).
What solutions have you tried so far?
I tried doing:
table.insert(Players_Complete, player.Name)
Players_Complete[player.Name] = score
but it errors as expecting a number.
Original script:
table.insert(Players_Complete, 1, player.Name)
Players_Complete[player.Name] = score
If you know how to fix, please let me know. Thanks!
Edit: Entire code is below.
local Players_Complete = {}
game.ReplicatedStorage.Server.OnServerEvent:Connect(function(player, result, score, timetaken)
local url = "not showing :)"
local http = game:GetService("HttpService")
local data
if result == "Passed." then
Players_Complete[player.UserId] = score
print(Players_Complete)
local success, errormessage = pcall(function()
local DataStoreService = game:GetService("DataStoreService")
local LevelStore = DataStoreService:GetDataStore("CurrentQuizzes")
LevelStore:SetAsync("QuizData", Players_Complete)
end)
if success then
else
warn(errormessage)
end
for key, value in pairs(Players_Complete) do
print(key .. " is " .. value)
end
data = {
["embeds"] = {
{
["title"] = "Quiz Results",
["description"] = "**Result**\n" .. result .. "\n\n**Score**\n" .. score .. "\n\n**Time Taken**\n" .. timetaken,
["url"] = "https://www.roblox.com/games/6323540528/",
["color"] = 65321,
["author"] = {
["name"] = player.Name,
["url"] = "https://www.roblox.com/users/" .. player.UserId .. "/profile"
},
["footer"] = {
["text"] = "Café Away Quiz Center",
["icon_url"] = "https://t6.rbxcdn.com/8da44bc016ce4b29627aeb3fd9c74172"
},
["thumbnail"] = {
["url"] = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. player.UserId .. "&width=420&height=420&format=png"
}
}
}
}
else
data = {
["embeds"] = {
{
["title"] = "Quiz Results",
["description"] = "**Result**\n" .. result .. "\n\n**Score**\n" .. score .. "\n\n**Time Taken**\n" .. timetaken,
["url"] = "https://www.roblox.com/games/6323540528/",
["color"] = 16711680,
["author"] = {
["name"] = player.Name,
["url"] = "https://www.roblox.com/users/" .. player.UserId .. "/profile"
},
["footer"] = {
["text"] = "Café Away Quiz Center",
["icon_url"] = "https://t6.rbxcdn.com/8da44bc016ce4b29627aeb3fd9c74172"
},
["thumbnail"] = {
["url"] = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. player.UserId .. "&width=420&height=420&format=png"
}
}
}
}
end
local finaldata = http:JSONEncode(data)
http:PostAsync(url, finaldata)
end)
game.Players.PlayerAdded:Connect(function(player)
local DataStoreService = game:GetService("DataStoreService")
local LevelStore = DataStoreService:GetDataStore("CurrentQuizzes")
local data
local success, errormessage = pcall(function()
data = LevelStore:GetAsync("QuizData")
end)
if success then
print(data)
Players_Complete = data
end
end)