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.
This is because you are making two leaderboard objects, roblox's PlayerlistModule.lua module uses FindFirstChild so it will only detect one of the leaderstats. In one of the scripts remove
ls.Name = "leaderstats"
and ls.Parent = player
then replace local ls = Instance.new("IntValue")
with local ls = player:FindFirstChild("leaderstats")