So I have a "Number Value" inside a brick and every 5 seconds I want it to add 1 to the current value. Here is what I have so far.
local Pos = script.Parent.Position local C = script.Parent.C if C.Value <= 5 then game.Soundscape.Bomb:Play() E = Instance.new("Explosion", script.Parent) E.BlastRadius = 190 E.BlastPressure = 50000 E.DestroyJointRadiusPercent = 100 E.Position = Vector3.new(Pos) else return end for i=1,5 do wait(5) C.Value +1 wait() end
To fix your problem, make sure you're making the value equal to itself, then add one.
for i = 1, 5 do wait(5) C.Value = C.Value + 1 end
If you want to add restrictions, you may do this:
for i = 1, 5 do wait(5) if C.Value < 5 then C.Value = C.Value + 1 end end
That way it prevents the 'for' loop from adding any more.
I would like to point out that your 'for' loop won't return back to the 'if' statement on line 3, therefore making it impossible to execute the 'if' statement unless if you disabled and re-enabled your script.
Instead of doing that, use the 'Changed' event since you're using a physical NumberValue object.
function onChanged() if C.Value <=5 then game.Soundscape.Bomb:Play() E = Instance.new("Explosion") -- I wouldn't define it's parent yet. E.BlastRadius = 190 E.BlastPressure = 50000 E.DestroyJointRadiusPercent = 100 E.Position = Vector3.new(Pos) E.Parent = script.Parent end end C.Changed:connect(onChanged)
Try:
x = game.Workspace.IntValue -- Path here while x<5 do -- Will only run if x is smaller than 5 x.Value = x.Value + 1 wait(5) end
EDIT:
Your problem was on line 14, you did:
C.Value +1
Instead of:
C.Value = C.Value+1
You can't just add one, like you did.
This won't work?
local C = script.Parent.C local Pos = script.Parent.Position for i = 1, 5 do wait(5) if C.Value > 5 then C.Value = C.Value + 1 end end function onChanged(E) if C.Value <=5 then game.Soundscape.Bomb:Play() E = Instance.new("Explosion") E.BlastRadius = 190 E.BlastPressure = 50000 E.DestroyJointRadiusPercent = 100 E.Position = Vector3.new(Pos) E.Parent = script.Parent end end C.Changed:connect(onChanged)