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.
Ok so I used the script that @2112Jay told me to use, and when I changed the leaderstat by going in to the players > ApexEMD(ME) > leaderstats folder > Win Streak > went to the properties and changed its value to 5 and Highest win streak didn’t change. I did also put them in server script and in the server-script-service. Do you know anything that could ruin the script?
I am not the final word on anything. I may be wrong; I tend to do that scraping for answers. Part of the process in finding a working solution. I’m trying to stick to your format and find what may be leading to the script not working as intended. The goal is simple: if the current win streak is higher than the stored highest win streak, update the highest win streak value to the current win streak. My post that I’m going to remove is more pushing for why this simplistic goal isn’t being implemented. Your reply is aiming at more of a problem than this single code chunk. I’m assuming the problem is in (I haven’t included the whole script because it’s unneeded) the rest of the script or the overall logic.
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
In itself, this chunk will never work and is partially irrelevant anyways. You are just checking 0 vs 0; nothing has been loaded with current data and nothing has been won at this point, streak or not, so there’s nothing to check vs stored data. This, as is, isn’t just a maybe syntax error; it’s a logic error.
The issue is that you run that line before setting the values/waiting for player data to load. That line should run once after data load and every time it changes in-game. Also you can get rid of the if statement and write this instead:
I have figured there are many ways to solve this problem I found a couple of ways to make it work once, but not in my game I believe there’s something affecting it.