Higher than giving wrong output

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)

try:

if tonumber(RealTimeScore.Text) >= tonumber(highScore.Text) then
1 Like

this strangly worked. thanks this helps alot

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.

so if i want to change the text into a different number i can just put in a number?

Yes it will be turned into a string automatically using some default format. If you want to manually control the format use string.format()

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.