Need help fixing my time bonus script

Alright, I’m designing this time trial racing game and each checkpoint you pass grants you a time bonus.

The problem consists of adding the time to the timer itself. Since I’m using this format (0:00) to display time the seconds go over 60.

I’m trying to make it where if the seconds gained from the time bonus exceeds the max amount second (59) then it adds a minute and the seconds left over from the bonus.

1 Like

Instead of having it as an IntValue, what if you have the 0:00 format as a StringValue?

Then with that you can set the variables for minutes, and seconds. Something like this:

local TimeFormat =  string:split(StringValue.Value, ":")

TLogic = {}

function TLogic.timeGate(Sec)
 
 local minutes = tonumber(TimeFormat[1])
 local seconds = tonumber(TimeFormat[2]) += Sec

 local leftOver = (Sec - 60)/2
 
 if seconds >= 59 then
  
  print(leftOver)

  local addMinute = minutes + 1
  local addSeconds = leftOver
 end
 print('Time Added - ' .. Sec .. ':' .. leftOver)
end

You can maneuver with this script to best fit your likings, might catch some errors…

Let me know if this script doesn’t work correctly; I made it without testing it (whoops).

Got two errors, one on line 20 “identifier expected error parsing the statement” and another stating "invalid argument #1 to ‘split’ (string expected, got table) "

local TimeFormat =  string:split(StringValue.Value, ":")

Change it to this:

local TimeFormat =  string:split(tostring(StringValue.Value, ":"))

If that doesn’t work, you can try this:

local Value = tostring(StringValue.Value)
local TimeFormat =  Value:split(":")

Also, you sure you’ve changed the StringValue to wherever your StringValue is located?

If it’s okay, could I have the file of the place so I could actually code it and test it?

Switching it to the last two lines fixed it thanks.

1 Like