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

Script won't run when script.Parent.Enable is Enabled, Why?

I've been searching for an hour and I can not find where the error is, can somebody help me solve this issue?

while wait do
	wait(0.3)
local minutes = 4
local seconds = 0
local hours = 0

if script.Parent.Enable == true then
local h = script.Parent
h.Parent = game.Workspace
for i = 1, (hours+1) do
for i = 1, (minutes+1) do
for i = 1, (seconds+1) do
if hours < 10 then
     if minutes < 10 then
            if seconds < 10 then
            h.Value = ""..hours..""..minutes..":"..seconds
            else
            h.Value = ""..hours..""..minutes..":"..seconds
            end
     else
             if seconds < 10 then
             h.Value = ""..hours..""..minutes..":"..seconds
             else
             h.Value = ""..hours..""..minutes..":"..seconds
             end
     end
else
     if minutes < 10 then
            if seconds < 10 then
            h.Value = hours..""..minutes..":"..seconds
            else
            h.Value = hours..""..minutes..":"..seconds
            end
     else
             if seconds < 10 then
             h.Value = hours..""..minutes..":"..seconds
             else
             h.Value = hours..""..minutes..":"..seconds
             end
     end
end
seconds = seconds - 1
wait(1)
end
seconds = 59
minutes = minutes - 1
end
minutes = 59
seconds = 59
hours = hours - 1
end
   end 
       end

3 answers

If script.Parent.Enable is a boolvalue then you would do script.Parent.Enable.Value, because we need to get the value, not a instance; Also you can shorten

if script.Parent.Enable.Value == true then

To

if script.Parent.Enable.Value then

Because Lua thinks every thing is true, except for false, and nil

If your trying to do a time system, you can experiment with os.date and os.time

Here is the os library : https://developer.roblox.com/api-reference/lua-docs/os

1 comment

0

I added "if script.Parent.Enable.Value == true then" but it still will not run when I set the boolvalue to true

Try now

wait()
local minutes = 4
local seconds = 0
local hours = 0

script.Parent.Enabled.Changed:Connect(function()
	if script.Parent.Enabled.Value == true then

	local h = script.Parent
	h.Parent = game.Workspace
	
	for i = 1, (hours+1) do
	for i = 1, (minutes+1) do
	for i = 1, (seconds+1) do

	if hours < 10 then
	     if minutes < 10 then
	            if seconds < 10 then
	            h.Value = ""..hours..""..minutes..":"..seconds
	            else
	            h.Value = ""..hours..""..minutes..":"..seconds
	            end
	     else
	             if seconds < 10 then
	             h.Value = ""..hours..""..minutes..":"..seconds
	             else
	             h.Value = ""..hours..""..minutes..":"..seconds
	             end
	     end
	else

	     if minutes < 10 then
	            if seconds < 10 then
	            h.Value = hours..""..minutes..":"..seconds
	            else
	            h.Value = hours..""..minutes..":"..seconds
	            end
	     else
	             if seconds < 10 then
	             h.Value = hours..""..minutes..":"..seconds
	             else
	             h.Value = hours..""..minutes..":"..seconds
	             end
	     end
	end

	seconds = seconds - 1
	wait(1)
	end
	seconds = 59
	minutes = minutes - 1
	end
	minutes = 59
	seconds = 59
	hours = hours - 1

		end 
	end
end)

3 comments

0

Still nothing

0

Do you even get anything in the output?

0

Oh, one sec, i'll update my code

The error is at line 7: if script.Parent.Enable == true then . It's actually supposed to be if script.Parent.Enabled == true then.

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