Help Me With This Script Please

So… I am trying to make a running for _ seconds but it just happends to be only 2 seconds when i seconds passed… The Script…

local j = script.Parent.Configuration
j:SetAttribute("runCount",0)
while true do
	wait(1)
	local i = 1
	i = i + 1
	warn(i)
	print(i)
	j:SetAttribute("runCount",i)
	script.Parent.Text = "RUNING FOR: "..j:GetAttribute("runCount").."secs"
end

Declare and set the variable i outside of your while loop. Currently, every loop, the variable is reset. as it is declared anew each time.

1 Like

You should define i outside of the loop:

local j = script.Parent.Configuration
j:SetAttribute("runCount", 0)

local i = 1

while true do
	wait(1)
	i = i + 1
	warn(i)
	print(i)
	j:SetAttribute("runCount", i)
	script.Parent.Text = "RUNNING FOR: " .. j:GetAttribute("runCount") .. " secs"
end

I’m not sure if that will solve your problem. Could you please elaborate on what you are trying to do?

Disclaimer: This code was partially or fully AI-generated from: https://chat.openai.com/chat

Thanks It Worked Well… i such a noob :smile: :smile:

Here is a better way of counting how long something happened in Roblox:

-- Set the start time of the timer
local startTime = tick()

-- Continuously update the timer and display the elapsed time
while true do
	task.wait(1)
	local elapsedTime = tick() - startTime
	print("Elapsed time: " .. elapsedTime .. " seconds")
end

Disclaimer: This code was partially or fully AI-generated from: https://chat.openai.com/chat

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.