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

Day/Night building Material does not change?

Asked by 6 years ago
Edited by SerpentineKing 6 years ago

This is the script here

1building = script.Parent
2if game.Lighting.ClockTime >= script.Parent.Night.Value then
3    wait(1)
4    building.Material = "Neon"
5elseif game.Lighting.ClockTime >= script.Parent.Day.Value then
6    building.Material = "Plastic"
7end

I try to make it so it will make the building neon if it's = to the number value I put (ex. 19) but it's not working when the day or the night comes

[SerpentineKing]: Input proper code format

0
hmmm clean it please? starmaq 1290 — 6y
0
You put it incorrectly.. wilsonsilva007 373 — 6y
0
I try to make it correct XD doesn't work bostaffmanbulgaria1 89 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

GENERAL PRACTICE

Use :GetService() to retrieve Lighting

Use :WaitForChild() to make sure an item exists before changing it.

Make sure to use local variables when a line, like "building" is meant to be inside a function that is not global.

Material is an Enum, not a String, so while the string may work some of the time, it is not always guaranteed.

Since you are checking that the ClockTime is greater than the day and night values, also make sure to have a check that the time is less than the night so the "day" change can run.

ISSUES

Your code needs to be placed within a function to work multiple times with the same activating requirements. Without the function, the code will only run once at the time the server is created. In the below example, I've used a :GetPropertyChangedSignal() to determine that the ClockTime of the Lighting is changed (as opposed to Brightness or another property).

REVISED SERVER SCRIPT

01local lighting = game:GetService("Lighting")
02local building = script.Parent
03local night = building:WaitForChild("Night").Value
04local day = building:WaitForChild("Day").Value
05 
06lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
07    if lighting.ClockTime >= night then
08        wait(1)
09        building.Material = Enum.Material.Neon
10    elseif lighting.ClockTime >= day and lighting.ClockTime < night then
11        building.Material = Enum.Material.Plastic
12    end
13end)
Ad

Answer this question