Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

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.

0

there's no such thing as a -= b in roblox lua

1 answer

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).

1 comment

0

Btw, if FoStat is a IntValue and you want to change its value, you have to type FoStat.Value.

This discussion is preserved as it was. New answers, comments, and votes are closed.