Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why PointLight dont enable?

Asked by 5 years ago

i want to make a alarm what will enable when is the core melting or freezeing. But it dont enables.

while true do
temp = game.Workspace.Temp.Value
if temp == 3000 then
script.Parent.PointLight.Enabled = true
elseif temp == 2700 then
script.Parent.PointLight.Enabled = false
elseif temp == 2200 then
script.Parent.PointLight.Enabled = false
elseif temp == -100 then
script.Parent.PointLight.Enabled = false
elseif temp == -300 then
script.Parent.PointLight.Enabled = false
else
script.Parent.PointLight.Enabled = true
end
wait()
end

1 answer

Log in to vote
0
Answered by 5 years ago

The reason for this is probably that you are only checking if the value is equivalent to a number, rather than seeing if it is lesser than / greater than that number, which leaves a number like 3001 or 0 to turn the point light on.

A couple of other things it would be great to do would be :

  • Properly indent your code

  • Use local variables if they aren't used outside of their scope

  • Try to find alternatives to using an infinite loop

I don't really know what you are trying to do with your light as you weren't really descriptive in your question, so here is my best estimate of what you were trying to do:

while true do
    local temp = workspace.Temp.Value
    local light  = script.Parent.Pointlight
    If temp >= 3000 or temp <= -300 then
        light.Enabled = true
    else
        light.Enabled = false
    end
    wait()
end
0
Its not working :C TrueMatejGamez 4 — 5y
Ad

Answer this question