So i have this script that checks how far away you are from the spawnlocation.
It also constandly checks if your highscore is lower then your current score away from the spawnlocation.
The problem is that it constandly thinks that the highscore is lower, while it isn’t.
How can i fix that the script thinks that its lower?
local startpart = game.Workspace:WaitForChild("SpawnLocation")
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local ScoreFrame = script.Parent.Score
local RealTimeScore = ScoreFrame.RealTimeScore
local highScore = ScoreFrame.HighScore
local function round(n)
return math.floor(n + 0.5)
end
RunService.RenderStepped:Connect(function()
RealTimeScore.Text = round((startpart.Position - player.Character:GetPivot().Position).Magnitude)
if RealTimeScore.Text >= highScore.Text then
warn("new highscore")
end
end)
It works because without tonumber() you are comparing two strings which doesn’t do anything particularly userful and unfortunately doesn’t warn you when you do it by accident. The value you get from .Text is always a string, but it will accept any value that is corecible to a string, like a number.