Make a counter smoothly go from 0 to 800 with a click detector

So I’m trying to get a counter go from 0 to 800 in a smooth transistion (Like going 1,2,3,4,5 and so on really fast until its at 800)
I have found a similar script;

local target = game.Workspace.Target

local ClickDetector = Instance.new("ClickDetector")

ClickDetector.Parent = target

local counter = script.Parent --This is the TextLable Gui

local clickCounter = 0

counter.Text = clickCounter

ClickDetector.MouseClick:Connect(function(ClickDetector)

clickCounter = clickCounter + 1

counter.Text = clickCounter

end)

I need it to go to 800 like I said in a smooth transistion instead of just adding “+ 1”. I’ve tried adding a “for” command instead of + 1 but it didn’t work
1fc6de0893221de98800f6de3534448d

2 Likes

Did you tried this?

for i = 0, 800, 1 do
   clickCounter = i
   wait(0.1)
end

That would be really bad, no one wants to wait 80 seconds. You should use tweenService
Code:

local tweenService = game:GetService("TweenService")
tweenService:Create(ClickDetector, TweenInfo.new(3), {Value = 800}):Play()

I typed this out in devForum so there may be typing errors

Couldn’t you use a number value and use TweenService to make it go to 800, then while this tween is happening keep constantly changing the text to display what the value is displaying?

Well he just need to change the wait() from 0.1 into 0.001

he also can use TweenService to make more smoother

Which part to I replace with:

for i = 0, 800, 1 do
   clickCounter = i
   wait(0.1)
end
1 Like

At which part do I put the code?

My Code:

local target = game.Workspace.Target

local ClickDetector = Instance.new("ClickDetector")

ClickDetector.Parent = target

local counter = script.Parent --This is the TextLable Gui

local clickCounter = 0

counter.Text = clickCounter

ClickDetector.MouseClick:Connect(function(ClickDetector)

for i = 0, 800, 1 do
   clickCounter = i
   wait(0.1)
end

counter.Text = clickCounter

end)

@TheZanderius Code:

local tweenService = game:GetService("TweenService")

local target = game.Workspace.Target

local ClickDetector = Instance.new("ClickDetector")

ClickDetector.Parent = target

local counter = script.Parent --This is the TextLable Gui

local clickCounter = 0

counter.Text = clickCounter

ClickDetector.MouseClick:Connect(function(ClickDetector)

tweenService:Create(ClickDetector, TweenInfo.new(3), {Value = 800}):Play()

counter.Text = clickCounter

end)

Just edited your code and added the TweenService that has been suggested above:


local target = game.Workspace.Target

local ClickDetector = Instance.new("ClickDetector")

ClickDetector.Parent = target

local counter = script.Parent --This is the TextLable Gui

local clickCounter = Instance.new("IntValue",script.Parent)

clickCounter.Changed:Connect(function(value)

counter.Text = tostring(value)

end)

counter.Text = clickCounter.Value

ClickDetector.MouseClick:Connect(function(ClickDetector)

game:GetService("TweenService"):Create(clickCounter,TweenInfo.new(2),{Value = 800}):Play() -- Change the number 2 to your speed in seconds

end)

2 Likes

Thank you very much, that worked.

3 Likes

Also thank you for your help :smiley: