So, I've got a game where you fling yourself off a ramp. I've got some code to detect magnitude and put it into a leaderstat, but I want to find the highest magnitude before death, and then add that to the leaderstat. Sort of like a currency system. Below is the code for the magnitude stat that I currently have.
local Players = game:GetService("Players")
local point = workspace.Wedge
local function find_distance(speed: number, character: Model)
local player = Players:GetPlayerFromCharacter(character)
local root_part = character:WaitForChild("HumanoidRootPart")
local leaderstats = player:WaitForChild("leaderstats")
local magnitude = leaderstats.Magnitude
magnitude.Value = (root_part.Position - point.Position).Magnitude
end
local function character_added(character)
print(character.ClassName)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Running:Connect(function(speed)
find_distance(speed, character)
end)
end
local function player_added(player: Player)
player.CharacterAdded:Connect(character_added)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local magnitude = Instance.new("IntValue")
magnitude.Name = "Magnitude"
magnitude.Parent = leaderstats
end
Players.PlayerAdded:Connect(player_added)

3 comments
Record whatever the last known highest magnitude was, then do not update the IntValue unless the calculated magnitude exceeded the record. Update the record as you update the IntValue.
That does sound like it could work, but im just not sure how to do that.
Actually, your IntValue already acts as the record.