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

Trying to loop an IntValue getting subtracted to a math.random, can I do that?

Asked by 4 years ago
Players = game:GetService("Players")
FoStat = game.Players.LocalPlayer.FoodStat
remoteEvent = game.ReplicatedStorage:WaitForChild("StatStart")
FoodStatOn = false

remoteEvent.OnServerEvent(function()
    FoodStatOn = true
    while FoodStatOn == true do
        wait(math.random(45, 120))
        FoStat - math.random(-3, -6)
    end
end)

FoStat - math.random on line 10 keeps getting an error expecting a function call or assignment. I've read and watched a bunch of tutorials and documentation on the while true do statement, can't find the problem.

0
I believe you meant `FoStat.Value -= math.random(-6, -3)`. First off, you need to get the values of IntValues by accessing its `.Value` property. Next, `math.random()` arguments go from min to max. If your min is bigger than your max, it will error. As for `a -= b` that is the same as doing `a = a - b`. zadobyte 692 — 4y
0
there's no such thing as a -= b in roblox lua WINDOWS10XPRO 438 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

In line 10, you got 2 mistakes. First, the first argument in math.random() needs to be a smaller number but -3 is greater than -6, swap them and the first mistake should be solved. Second, you cannot do FoStat -, you have to do FoStat -= math.random(-6, -3) or FoStat = FoStat - math.random(-6, -3).

0
Btw, if FoStat is a IntValue and you want to change its value, you have to type FoStat.Value. NotTheChara 191 — 4y
Ad

Answer this question