I am trying to write a script that records and saves kills and deaths through games and it has a points system for a leader board in a hub game where you join the smaller games from, you get a point per kill and -1 point per death and I’ve run into trouble with this script. Saving its data to transfer over to the hub game and into other smaller games that are connected to it, and getting a point a kill/losing a point on death isn’t working, I believe this is a logic error because no errors are outputted. Not willing to pay, that was an error I, copy pasted from another one of my posts… Sorry aha I think I’m missing a module script.
There is no error message
Here is a copy of the code and how it tries the calculation. Alongside the leader stats script itself.
local PointsValue = Instance.new("NumberValue", Player)
PointsValue.Name = "FP"
PointsValue.Parent = Player.leaderstats
local FetchedPoints
local succ, err = pcall(function()
FetchedPoints = FWMPoints:GetAsync(tostring(Player.UserId))
end)
if succ then
PointsValue.Value = FetchedPoints
end
end
(followed by this wayy at the bottom)
if UpdatePointsLeaderboard and UpdatePointsLeaderboard:IsA("RemoteEvent") then
while true do
for _, Player in pairs(Players:GetPlayers()) do
if Player.UserId <= 0 then
continue
end
while (not PlayerDatas[Player]) and Player do
task.wait()
end
local Find = DataHandler.New(PlayerDatas[Player], Player.UserId)
if Find and Find:getStats() then
local playerStats = Find:getStats()
local success, failed = pcall(function()
return Points:UpdateAsync(Player.UserId, function()
return playerStats.KOs - playerStats.WOs
end)
end)
print(success and "Successfully saved!" or failed)
end
end
local sortedTop: Instance | DataStorePages = Points:GetSortedAsync(false, 10)
if sortedTop and sortedTop:IsA("DataStorePages") then
local currentTopPlayers = sortedTop:GetCurrentPage()
UpdatePointsLeaderboard:FireAllClients(currentTopPlayers)
end
task.wait(60)
end
end
(and this is the script for the kills and deaths leader board)
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local kills = Instance.new("IntValue")
kills.Name = "KOs"
kills.Parent = stats
local deaths = Instance.new("IntValue")
deaths.Name = "WOs"
deaths.Parent = stats
plr.CharacterAdded:connect(function(char)
local humanoid
repeat
humanoid = char:FindFirstChild("Humanoid")
wait()
until humanoid
humanoid.Died:connect(function()
deaths.Value = deaths.Value + 1
local tag = humanoid:FindFirstChild("creator")
if tag then
local killer = tag.Value
if killer then
killer.leaderstats.KOs.Value = killer.leaderstats.KOs.Value + 1
end
end
end)
end)
end)