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

How can I get my variable to stop resetting to zero?

Trying to make a counter for how many times you have touched "Brick1", but every time the script runs it resets to zero. Was wondering how i can declare the variable only once and have it NOT reset when the script runs again.

My code:

TimesFound = 0
Increment = 1
TimesFound = TimesFound + Increment

Part = game.Workspace.Brick1

function RandMove()
	print(TimesFound + Increment)
    Part.Position = Vector3.new(math.random(0, 100), 5, math.random(0, 100))
end
 
RandMove()
 
Touched = Part.Touched:Connect(RandMove)



1 answer

TimesFound1 = 0
Increment = 1
TimesFound2 = TimesFound1 == TimesFound1 + Increment

Part = game.Workspace.Brick1

function RandMove()
    print(TimesFound2)
    Part.Position = Vector3.new(math.random(0, 100), 5, math.random(0, 100))
end

RandMove()

Touched = Part.Touched:Connect(RandMove)



8 comments

0

thanks

0

wait... getting a new error: Expected identifier when parsing expression, got '=' on line 3

0

i edited it should work now

0

i edited it should work now

0

i edited it should work now

0

i edited it should work now

0

i edited it should work now

0

i edited it should work now

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