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

How do I do arithmetic with attribute?

Asked by 3 years ago
1SecTime = game.workspace:GetAttribute("Second")
2while true do
3    wait(1)
4    SecTime = SecTime + 1
5    game.Workspace:SetAttribute("Second", SecTime)
6end

It gives me a error, attempting to do arithmetic at line 4. How do i fix it

0
haven’t used attributes but I’m pretty sure I remember that you can choose what type they are (string, number, etc) you probably made it a string by accident Speedmask 661 — 3y

2 answers

Log in to vote
0
Answered by
RAFA1608 543 Moderation Voter
3 years ago

Hello!

You see, strings can not be added, subtracted, multiplied, whatever, with a number. What you can do, is to first convert the string to a number, and then convert it back to a string.

1local string = "200"
2 
3local finalnumber = tonumber(string) + 300
4 
5local finalstring = tostring(finalnumber)

If you're confused, you can go here for an article about strings and their behavior.

I hope this helps!

Ad
Log in to vote
0
Answered by
0hsa 193
3 years ago

your code was much deprecation

1local start = os.time()
2 
3while true do
4    local now = os.time()
5    workspace:SetAttribute("Second", math.floor(now - start))
6    wait(0.5)
7end

Answer this question