When the button is pressed, fuel should be += 1

When the Doldur button is pressed, the Depo dolum location will increase by 1 every 1 second to reach 10 and stop.

local btn = game.StarterGui:FindFirstChild("ScreenGui").DoldurBtn
local mik = game.StarterGui:FindFirstChild("ScreenGui").DepoDolum.Miktar
local depo = 10
local fuel = 0

btn.MouseButton1Click:Connect(function()
	fuel = mik.Text
	for i=fuel, 10 do
		wait(1)
		print(i)
		i += 1
		print(i)
		if i == 10 then
			break
		end
	end
end)

image

2 Likes

What exactly is the problem though, you just told us what it supposed to do

2 Likes

What could it be??? I said what needs to happen and it doesn’t work

I don’t think you can use a for loop on a text.


fuel = mik.Text
	for i=fuel, 10 do
		wait(1)
		print(i)
		i += 1
		print(i)
		if i == 10 then
			break
		end
	end

So instead maybe try this?


fuel = 1
	for i=fuel, 10 do
		wait(1)
		print(i)
		if i == 10 then
			break
		end
	end

For testing purposes.

1 Like
for i = 1, 10 do
	mik.Text = tostring(i)
    task.wait(1)
end
1 Like

Increasing i by 1 wouldn’t work because the for loop automatically increases it by 1 every loop it does.
try removing the

i += 1

It is also unnecessary to include a break since it would also break on its own when the 10 loops are completed.

Another issue is that you are attempting to use a string where a number should be.
If you get rid of the variable it would read,

for i="0", 10 do

which wouldn’t work.

Try this

local btn = game.StarterGui:FindFirstChild("ScreenGui").DoldurBtn
local mik = game.StarterGui:FindFirstChild("ScreenGui").DepoDolum.Miktar
local depo = 10
local fuel = 0

btn.MouseButton1Click:Connect(function()
	fuel = tonumber(mik.Text)
	for i=fuel, 10 do
		wait(1)
		print("Interation Number:"..i)
mik.Text = tostring(fuel)
		if i == 10 then
			break
		end
	end
end)
1 Like