This is an example of my leveling system and it says fired to much i want it to fire as much as neccesary so that i can stack them
local val = Instance.new("NumberValue")
val.Value = 0
val.Parent = workspace
local function onChange()
if val.Value >= 15 then
val.Value -= 15
print("Changed")
end
end
val:GetPropertyChangedSignal("Value"):Connect(onChange)
val.Value = 999
Your value is getting ran 6 times because Because the Value is changing in the function “-=” and that value is getting changed so it keeps Making that loop
local numberValue = Instance.new("NumberValue")
numberValue.Changed:Connect(function(value)
print("Changed", value)
end)
numberValue.Parent = workspace
local value = 999
value -= math.floor(value / 15) * 15 -- this is the same as doing (while value >= 15 do value -= 15 end)
numberValue.Value = value
-- if you want to know how many times 15 was deducted from 999
print("Changed", math.floor(value / 15) , "Times")
local val = Instance.new("NumberValue")
val.Parent = workspace
val.Value = 0
local function onChange()
local Connection
Connection = val:GetPropertyChangedSignal("Value"):Connect(function()
Connection:Disconnect()
if val.Value >= 15 then
val.Value -= 15
print("Changed")
end
onChange()
end)
end
onChange()