Why doesnt my script work?

Why doesn’t my script work? It should here it is

local Values = game:GetService("ServerStorage").Values.ShopPrices:GetChildren() --Cost values of the items
local Lighting = game:GetService("Lighting") -- Lighting service

local Bool2 = true

local Bool = false

local chance

while Bool == false do
	wait(0.01)
	if Lighting.ClockTime >= 7 or Lighting.ClockTime <= 18.5 then
		Bool = true
		Bool2 = false
		chance = math.random(1, 5) --Okay so this part works until the next day when it doesn't do anything
		print(chance)
		if chance <= 2 then
		for i = 1, #Values do
			wait(1)
			Values[i].Value = Values[i].Value + 1
		end
		
		if chance >= 3 then				
			for i = 1, #Values do
				OrgPrices = Values[i].OrgPrice
				if Values[i].Value > OrgPrices then
				wait(1)
				Values[i].Value = Values[i].Value - 1
					end
				end
			end	
		end
	end
end

while Bool2 == false do
	wait(0.01)
	if Lighting.ClockTime>= 18.5 or Lighting.ClockTime <= 7 then
		Bool = false
		Bool2 = true
	end
end

I don’t know why this is happening. If anyone can help me that would be great Thanks

What’s not working again? Are the prices not lowering or sum?

--[[

                      _____                                  __                 
  ____ _____ ________/ ____\__  ___ ____     ____   ____   _/  |_  ____ ______  
_/ __ \\__  \\_  __ \   __\\  \/  //    \   /  _ \ /    \  \   __\/  _ \\____ \ 
\  ___/ / __ \|  | \/|  |   >    <|   |  \ (  <_> )   |  \  |  | (  <_> )  |_> >
 \___  >____  /__|   |__|  /__/\_ \___|  /  \____/|___|  /  |__|  \____/|   __/ 
     \/     \/                   \/    \/              \/               |__|    
                                                                          
                                          
]]

-- Services
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")

-- Misc ok
local Values = ServerStorage.Values.ShopPrices:GetChildren()
local Bool = false
local Bool2 = true
local chance


local function increaseValues()
	for i = 1, #Values do
		wait(1)
		Values[i].Value = Values[i].Value + 1
	end
end


local function reset()
	for i = 1, #Values do
		local originalPrice = Values[i].OrgPrice
		if Values[i].Value > originalPrice then
			wait(1)
			Values[i].Value = Values[i].Value - 1
		end
	end
end


local function PriceAdjusting()
	chance = math.random(1, 5)
	print(chance) -- Checking chance

	if chance <= 2 then
		increaseValues()
	elseif chance >= 3 then
		reset()
	end
end


local function Day()
	return Lighting.ClockTime >= 7 and Lighting.ClockTime <= 18.5
end

local function Night()
	return Lighting.ClockTime > 18.5 or Lighting.ClockTime < 7
end


while not Bool do
	task.wait(1)
	if Day() then
		Bool = true
		Bool2 = false
		PriceAdjusting()
	end
end

while not Bool2 do
	task.wait(1)
	if Night() then -- What you gonna do ? just incase
		Bool = false
		Bool2 = true
	end
end


I dont know why there are two bools, but I assume they’re for the night feature. Here are a few changes I made:

  1. Changed the wait time from 0.01 seconds to 1 second (using 0.01 is just a bad habit).
  2. Made the code more readable.
  3. Used day and night formats based on my understanding of your script.

can you send the output ?

The issues I have noticed are

  1. The While loops run continuously without resetting correctly for day/night cycles
  2. Your condition checks (>= 7 or <= 18.5) may cause issues, especially if the day to night cycle moves from one condition to the next
  3. You don’t need two separate while loops. A single loop with proper condition checks should be enough

This version of your script should work with all your issues solved hopefully, just make sure to ensure that each Value object has a OrgPrice attribute, or you can adjust the code to reference how the original prices are stored in your game

local Values = game:GetService("ServerStorage").Values.ShopPrices:GetChildren() --Cost values of the items
local Lighting = game:GetService("Lighting") -- Lighting service

local Bool = true  -- Indicates if it's day (true) or night (false)
local chance

while true do  -- Keep the loop running indefinitely
    wait(1)  -- Check the clock once per second

    -- Check if it's day (7 AM to 6:30 PM)
    if Lighting.ClockTime >= 7 and Lighting.ClockTime <= 18.5 and Bool == false then
        Bool = true  -- Set to day mode
        chance = math.random(1, 5)  -- Random chance for shop prices

        print("Daytime, chance:", chance)
        
        -- Increase prices if chance is less than or equal to 2
        if chance <= 2 then
            for i = 1, #Values do
                wait(1)
                Values[i].Value = Values[i].Value + 1
            end
        -- Decrease prices if chance is greater than or equal to 3
        elseif chance >= 3 then
            for i = 1, #Values do
                local OrgPrices = Values[i]:GetAttribute("OrgPrice") or 0 -- Assuming OrgPrice is an attribute
                if Values[i].Value > OrgPrices then
                    wait(1)
                    Values[i].Value = Values[i].Value - 1
                end
            end
        end
        
    -- Check if it's night (6:30 PM to 7 AM)
    elseif (Lighting.ClockTime >= 18.5 or Lighting.ClockTime <= 7) and Bool == true then
        Bool = false  -- Set to night mode
        print("Nighttime - shop closed or different prices")
    end
end