Loop won't Run (attempt to compare string and function)

Hello,

I recently created this script and changed it around a little. The Loop doesn’t run, and in Output it says, “Attempt to compare string and function”. Any help will be appreciated. The code is as follows (without indents):

local terrain = game.Workspace.Terrain

local time = game.Lighting.ClockTime

local daynight = script.Parent.DayNight.Value

print(“gotpastcode3”)

local colorValue = Instance.new(“Color3Value”)

colorValue.Value = terrain:GetMaterialColor(“Grass”)

colorValue.Parent = script.Parent

print(“gotpastcode2”)

colorValue:GetPropertyChangedSignal(“Value”):connect(function()

terrain:SetMaterialColor(“Grass”, colorValue.Value)

end)

print(“gotpastcode1”)

local tweenInfo = TweenInfo.new(60, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

local Night = game:GetService(“TweenService”):Create(colorValue, tweenInfo, {Value = Color3.fromRGB(91, 122, 380 )})

local Day = game:GetService(“TweenService”):Create(colorValue, tweenInfo, {Value = Color3.fromRGB(110, 148, 70)})

print(“got past code”)

while true do

print(“Looped”)

if time >= “21” or 21 then

Night:Play()

print(“Tweened”)

daynight = 1

wait(0.1)

end

if time >= “6” or 6 then

Day:Play()

print"Went back"

daynight = 0

wait(0.1)

end

wait(0.1)

end

R3M1X

Edit 1- the lines that are being mentioned are the if’s

1 Like

time is a keyword, which is an which is an in-built function. Try choosing a different name for the variable. Perhaps capital?

2 Likes

That was the problem all along! Thanks for your help!

R3M1X

1 Like

You also seem to have issue with your logic.

While it makes sense what you’re trying to do… Computers are incredibly dumb and you need to be specific.

if time > "6" or 6 then
-- Their are two issues here is
-- You cannot do mathematical operations on Strings 'time > "6"'
--also...
-- 'or 6'  will always return true.
-- you're not comparing it to another value, you're checking if it exists.


--Correction
if time > 6 then