Okay I am trying to compare leaderstats using > and <, And I am trying to compare The “Win Streak” And “Highest Win Streak”, if the “Win Streak” is greater than “Highest Win Streak” then for that player “Highest Win Streak” changes to “Win Streak”. Why doesent it work?
Here is the script:
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = stats
local WinStreak = Instance.new("IntValue")
WinStreak.Name = "Win Streak"
WinStreak.Parent = stats
local WinStreakH = Instance.new("IntValue")
WinStreakH.Name = "Highest Win Streak"
WinStreakH.Parent = stats
if WinStreakH.Value < WinStreak.Value then
WinStreakH.Value = WinStreak.Value
end
(I haven’t included the whole script because it’s unneeded)
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local dataModule = nil
if ServerStorage:FindFirstChild("Data") then
dataModule = require(ServerStorage:FindFirstChild("Data"))
elseif game:GetService("ServerScriptService"):FindFirstChild("Data") then
dataModule = require(game:GetService("ServerScriptService"):FindFirstChild("Data"))
else
warn("Data module not found!")
dataModule = {}
end
local function onPlayerAdded(player)
print("Player added:", player.Name)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = stats
local WinStreak = Instance.new("IntValue")
WinStreak.Name = "Win Streak"
WinStreak.Parent = stats
local WinStreakH = Instance.new("IntValue")
WinStreakH.Name = "Highest Win Streak"
WinStreakH.Parent = stats
if WinStreakH.value < WinStreak.value then
WinStreakH.Value = WinStreak.Value
end
local pdata = dataModule[player.UserId]
if pdata then
print("Loaded data for", player.Name, pdata)
Wins.Value = pdata.Wins or 0
WinStreak.Value = pdata.WinStreak or 0
WinStreakH.Value = pdata.WinStreakH or 0
else
print("No data found for", player.Name)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Each Value object is going to have 0 stored in it by default. Your code initializes their values only after you load the player data. I’m not sure what you’re going for, but you should probably perform the check you have repeatedly over time or when WinStreak’s Value updates. As it stands now, you’re comparing 0 < 0 once and then never again.
The comparison between Win Streak and Highest Win Streak was done immediately after creating the Int Values, outside of any event or listener. At that moment, all values are still 0, so the condition WinStreakH.Value < WinStreak.Value never becomes true.
--ServerScript in ServerScriptService
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = stats
local WinStreak = Instance.new("IntValue")
WinStreak.Name = "Win Streak"
WinStreak.Parent = stats
local WinStreakH = Instance.new("IntValue")
WinStreakH.Name = "Highest Win Streak"
WinStreakH.Parent = stats
local currentStreak = WinStreak
local highestStreak = WinStreakH
local highest = highestStreak.Value
currentStreak:GetPropertyChangedSignal("Value"):Connect(function()
local newStreak = currentStreak.Value
if newStreak > highest then
highest = newStreak
highestStreak.Value = highest
end
end)
end)
--ServerScript in ServerScriptService --mock test
local players = game:GetService("Players")
task.wait(5) print("start test")
local plr = players:FindFirstChildOfClass("Player")
if not plr then return end
local stats = plr:WaitForChild("leaderstats")
local currentStreak = stats:WaitForChild("Win Streak")
local highestStreak = stats:WaitForChild("Highest Win Streak")
task.wait(1)
currentStreak.Value = 1
task.wait(1)
currentStreak.Value = 2
task.wait(1)
currentStreak.Value = 3
task.wait(1)
currentStreak.Value = 4
task.wait(1)
print("Final Highest", highestStreak.Value)
Notice I’m using .Value only when needed. The rest is set up as “working with” variables. Reducing repeated .Value lookups and working with local variables helps prevent logic mistakes and keeps comparisons clearer. It does not change performance in any meaningful way, but it improves clarity and reduces accidental misuse of .Value. More of a preference thing and consistency. This is part of top-down design.