Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[SOLVED] Why is this line throwing an error?

Asked by
trogyssy 221 Moderation Voter
10 years ago
--Seconds, Minutes, and Goal are IntValues
--IsRunning is a BoolValue

local seconds=Workspace.Timer.Seconds.Value
local minutes=Workspace.Timer.Minutes.Value
local started=false
local running
if Workspace.Timer.IsRunning.Value==true then
    running="Counting..."
else
    if started then
        running="Paused"
    else        
        running="Not started yet"
    end
end
local goal=Workspace.Timer.Goal.Value

function updatetext()
    script.Parent.TimeLeft.Text=(goal-minutes):tostring()..":"..seconds:tostring()
    script.Parent.IsActive.Text=running
end
updatetext()


Workspace.Timer.Seconds.Changed:connect(function(v)
    seconds=v
    updatetext()
end)

Workspace.Timer.Minutes.Changed:connect(function(v)
    minutes=v
    updatetext()
end)

Workspace.Timer.IsRunning.Changed:connect(function(v)
    if v==true then
        running="The timer is running"
        started=true
    elseif v==false then
        if started then
            local running="Paused"
        else
            local running="Not started yet"
        end
    end
    updatetext()
end)

12:28:41.266 - Players.Player1.PlayerGui.RaidTimerGui.Timer.UpdateGui:20: attempt to index a number value 12:28:41.269 - Stack Begin 12:28:41.269 - Script 'Players.Player1.PlayerGui.RaidTimerGui.Timer.UpdateGui', Line 20 - global updatetext 12:28:41.270 - Script 'Players.Player1.PlayerGui.RaidTimerGui.Timer.UpdateGui', Line 23 12:28:41.270 - Stack End

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

You cannot use tostring as a method of numbers; numbers do not have members.

a:b() is sugar for a.b(a), and (5).tostring is clearly not valid.

Replace those uses of value:tostring() with tostring(value).


It should be noted, however, that the tostring in this case is unnecessary. Numbers, when experiencing concatenation, are converted to strings automatically.

0
thank you trogyssy 221 — 10y
Ad

Answer this question