I'm making this hangout game and I'm currently working on a leaderboard for how much time people have that shows the top 3.
Heres a Image of what the leaderboard looks like, Gyazo Image
It doesn't even save the players data to the data store because of a http error.
Code:
local Model = workspace:WaitForChild("TOP_TIMES")
local First = Model:WaitForChild("First")
local Second = Model:WaitForChild("Second")
local Third = Model:WaitForChild("Third")
local First_Obj = {First:WaitForChild("PName"), First:WaitForChild("PTime")}
local Second_Obj = {Second:WaitForChild("PName"), Second:WaitForChild("PTime")}
local Third_Obj = {Third:WaitForChild("PName"), Third:WaitForChild("PTime")}
local Characters = Model:WaitForChild("Characters")
local First_Position = Characters:WaitForChild("First").PrimaryPart.Position
local Second_Position = Characters:WaitForChild("Second").PrimaryPart.Position
local Third_Position = Characters:WaitForChild("Third").PrimaryPart.Position
Characters:ClearAllChildren()
local Ordered_Data_Store = game:GetService("DataStoreService"):GetOrderedDataStore("ORDERED_TIME_DATA")
local Data_Key = "~~~"
local Players = game:GetService("Players")
function GET_TOP_THREE()
print("GETTING TOP THREE")
local Ascending = false
local PageSize = 3
local Pages = Ordered_Data_Store:GetSortedAsync(Ascending, PageSize)
local Top_Three = Pages:GetCurrentPage()
print("TOP THREE: ")
for i,v in pairs(Top_Three) do
print("I: "..i)
print("V: "..v)
end
return Top_Three
end
function LOAD_TOP_THREE()
print("LOADING TOP THREE")
local TOP_THREE = GET_TOP_THREE()
if #Characters:GetChildren() > 0 then
Characters:ClearAllChildren()
end
for rank, data in pairs(TOP_THREE) do
print("RANK: "..rank)
print("DATA: "..data)
local User_ID = data[1]
local Player_Time = data[2]
if rank == 1 then
print("IS RANK 1")
First_Obj[1].UI.TextLabel.Text = Players:GetNameFromUserIdAsync(User_ID)
First_Obj[2].UI.TextLabel.Text = Player_Time
-- LOAD CHARACTER IN
local Humanoid_Desc = Players:GetHumanoidDescriptionFromUserId(User_ID)
local Character_Model = Players:CreateHumanoidModelFromDescription(Humanoid_Desc, Enum.HumanoidRigType.R15)
Character_Model:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
Character_Model:WaitForChild("Humanoid").MaxHealth = math.huge()
for _,v in pairs(Character_Model:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
Character_Model.Parent = Characters
Character_Model:SetPrimaryPartCFrame(First_Position)
elseif rank == 2 then
print("IS RANK 2")
Second_Obj[1].UI.TextLabel.Text = Players:GetNameFromUserIdAsync(User_ID)
Second_Obj[2].UI.TextLabel.Text = Player_Time
-- LOAD CHARACTER IN
local Humanoid_Desc = Players:GetHumanoidDescriptionFromUserId(User_ID)
local Character_Model = Players:CreateHumanoidModelFromDescription(Humanoid_Desc, Enum.HumanoidRigType.R15)
Character_Model:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
Character_Model:WaitForChild("Humanoid").MaxHealth = math.huge()
for _,v in pairs(Character_Model:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
Character_Model.Parent = Characters
Character_Model:SetPrimaryPartCFrame(Second_Position)
elseif rank == 3 then
print("IS RANK 3")
Third_Obj[1].UI.TextLabel.Text = Players:GetNameFromUserIdAsync(User_ID)
Third_Obj[2].UI.TextLabel.Text = Player_Time
-- LOAD CHARACTER IN
local Humanoid_Desc = Players:GetHumanoidDescriptionFromUserId(User_ID)
local Character_Model = Players:CreateHumanoidModelFromDescription(Humanoid_Desc, Enum.HumanoidRigType.R15)
Character_Model:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
Character_Model:WaitForChild("Humanoid").MaxHealth = math.huge()
for _,v in pairs(Character_Model:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
Character_Model.Parent = Characters
Character_Model:SetPrimaryPartCFrame(Third_Position)
end
end
end
Players.PlayerRemoving:Connect(function(Player)
local leaderstats = Player:FindFirstChild("leaderstats")
local Player_Time = leaderstats:FindFirstChild("Time")
print("PLAYER TIME: "..Player_Time.Value)
Ordered_Data_Store:SetAsync(Player.UserId, Player_Time.Value)
end)
Players.PlayerAdded:Connect(function(Player)
local leaderstats = Player:WaitForChild("leaderstats")
local Player_Time = leaderstats:WaitForChild("Time")
print("PLAYER TIME: "..Player_Time.Value)
Ordered_Data_Store:SetAsync(Player.UserId, Player_Time.Value)
end)
LOAD_TOP_THREE()
while wait(60) do
LOAD_TOP_THREE()
end
Error:
502: API Services rejected request with error. HTTP 400 (Bad Request)
The error is from when it does SetAsync to save the data
And I don't know what the problem is with that.
Any help is appreciated :)
