Expected identifier when parsing variable name?

Every time I script I always get expected identifier when parsing variable name heres what I used today, wait(20) function script.Parent.BackgroundTransprancy - 0.10
if script.Parent.BackgroundTransprancy = 0 then lighting.TimeOfDay = 0:00:00
Anybody know how to fix it?

1 Like

(a) Use ```lua {your code here} ```` so it’s easier to read next time you use the forum.

(b) From what I can see, you are not giving the function a name:

wait(20) function script.Parent.BackgroundTransprancy - 0.10
if script.Parent.BackgroundTransprancy = 0 then lighting.TimeOfDay = 0:00:00: 

should be

wait(20) 
function name() 
    script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.10
    if script.Parent.BackgroundTransparency = 0 then 
        lighting.TimeOfDay = 0:00:00
    end

(c) From what it seems, you don’t have much experience in scripting, so I would check out some beginner tutorials elsewhere on the forum.

Have a good day!

The = 0 then is having a problem too, I’m using…

wait(20)
function name()
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.10
if script.Parent.BackgroundTransparency = 0 then
lighting.TimeOfDay = 0:00:00
end

One = is for assignment. Two = is for comparing if 2 values are equal to each other. Also Lighting.TimeofDay is a string.

wait(20)
function name()
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.10
if script.Parent.BackgroundTransparency == 0 then
lighting.TimeOfDay = "0:00:00"
end

Also i’m pretty sure you are missing an end unless that’s not your whole script

1 Like

I used that and then output said to use end to close function at line 2 so I did then Lighting wasn’t found so then I used workspace.Lighting.TimeOfDay, would that work?
wait(20)

function name()

end

script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.10

if script.Parent.BackgroundTransparency == 0 then

workspace.Lighting.TimeOfDay = “0:00:00”

end

“no spaces btw it just glitched”

That means you are missing an end it should be:

function name()
 script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency - 0.10
  if script.Parent.BackgroundTransparency == 0 then
   workspace.Lighting.TimeOfDay = "0:00:00"
  end
end

Also if that doesn’t work it might be because time of day is property of the lighting service in that case you could do:

local Lighting = game:GetService("Lighting")
Lighting.TimeOfDay = "0:00:00"
1 Like

Don’t forget to call the function via name() !

It still worked without the second end, but I will mark solution anyway.

Thats because you took it out of the function anyway.
Which works, but you should research on why functions are useful

1 Like