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

How to trigger a value to add by one? Help!

For some reason the int Value "Hit" will not go up by one at all when "movenumber" gets to a certain position.

Help!

local movenumber = script.Parent
local Hit = script.Parent.MillisecondsOnesPlaceHitValue


while true do
	
wait(0.01)
movenumber.Position =  UDim2.new(0,0,0,0)
wait(0.01)
 movenumber.Position =  UDim2.new(0,-16,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-33,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-50,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-66,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-82,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-99,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-116,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-132,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-148,0,0)
wait(0.001)
movenumber.Position = UDim2.new(0,-160,0,0)
end 



if movenumber.Position == UDim2.new(0,-160,0,0)
	then Hit.Value = Hit.Value + 1
	end --this is not triggering, why exacty is it not triggering is my question?

2 comments

0

Do you want a gui to move? Or just a value to add by one every time?

0

to add by one every time.

1 answer

✓ Accepted answer

Looking at your script, if you want the value hit to add one everytime the position of movenumber reaches a certain point is actually quite simple, your while loop continuously loops until a certain criteria is reached, but since you put while true do it will go forever.

Every time a while loop goes through it has to get from point A The start to point B The End therefore your if statement is not needed as the while loop will go through all the code from a to b so you can just add the hit.Value = hit.Value + 1 at the end like this:

local movenumber = script.Parent
local Hit = script.Parent.MillisecondsOnesPlaceHitValue


while true do

wait(0.01)
movenumber.Position =  UDim2.new(0,0,0,0)
wait(0.01)
 movenumber.Position =  UDim2.new(0,-16,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-33,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-50,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-66,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-82,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-99,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-116,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-132,0,0)
wait(0.01)
 movenumber.Position = UDim2.new(0,-148,0,0)
wait(0.001)
movenumber.Position = UDim2.new(0,-160,0,0)
Hit.Value = Hit.Value + 1
end 

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