In my group game, I have 2 scripts for leaderboards and 1 for a point database. The first one is a point leaderboard and the other is a rank leaderboard for a group. When I use the points, the rank leaderboard doesn't work and vice versa. I am trying to debug but can't find the error.
Here is the AutoPoints script, in ServerScriptStorage:
amount = 1
timedelay = 180
currencyname = "Points"
while true do
wait(timedelay)
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") and v then
v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
end
end
end
Here is the PointDatabase script, in ServerScriptStorage:
-- NOTE FROM TROLLIANTBOT:
-- The points will not save if the game crashes.
-- The server can only take a number of requests per minute:
-- Getting Points: 60 + NumberOfPlayers X 10.
-- Saving Points: 60 + NumberOfPlayers X 10.
local DataStoreService = game:GetService("DataStoreService")
local PointSave = DataStoreService:GetDataStore("PointSave")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = PointSave:GetAsync(player.UserId)
end)
if success then
points.Value = data
else
print("There was an error whilst loading your points.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
PointSave:SetAsync(player.UserId,player.leaderstats.Points.Value)
end)
if success then
print("Points saved!")
else
print("Points were not saved due to an error.")
warn(errormessage)
end
end)
And finally, here is the RankLeaderboard script, in ServerScriptStorage:
function added(player)
local ls = Instance.new("IntValue")
ls.Name = "leaderstats"
local role = Instance.new("StringValue")
role.Name = "Rank"
role.Value = player:GetRoleInGroup(5243394)
local Points = Instance.new("NumberValue")
Points.Name = "Points"
Points.Parent = ls
ls.Parent = player
role.Parent = ls
end
game.Players.PlayerAdded:connect(added)
If you have a fix, please answer. It would be really appreciated.

3 comments
Have you tried combining these into 1 simultaneous working script, besides the while loop?
Oops, sorry about not adding player to my findfirstchild. Updated my answser
Thanks!