Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can some help change material at Time A and Time B?

Can someone help me edit this script to change to Neon when it reaches a certain time, but changes back to SmoothPlastic when it reaches another certain time?

local Lighting = game:GetService("Lighting");

-- Our while loop
while true do

-- Checking if the time is 18 or more.
if Lighting.ClockTime >= 18 then

    -- Let's change the lamp's material to Neon!
    script.Parent.BrickColor = BrickColor.new("Pink")

    else

    -- Change it to SmoothPlastic if it isn't late :D
    script.Parent.Material = Enum.Material.SmoothPlastic;
end

wait(1) -- Waits a second before continuing
end

2 answers

✓ Accepted answer

Instead of using a while loop, connect to :GetPropertyChangedSignal() or LightingChanged.

local lighting = game:GetService("Lighting")

lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function() 
	-- your code here
end)

To change a part's material to neon, you do it in thes same way that you did for SmoothPlastic, but replacing it with Neon

part.Material = Enum.Material.Neon

Documentation on GetPropertyChangedSignal, Materials

pink isnt a material, its a colour.

local Lighting = game:GetService("Lighting");
while true do
	if Lighting.ClockTime >= 18 then
   		script.Parent.Material = Enum.material.Neon
		script.Parent.BrickColor = BrickColor.new("Pink")
   		else
    		script.Parent.Material = Enum.Material.SmoothPlastic;
	end
wait(1)
end

1 comment

0

oops forget about the brickcolor

This discussion is preserved as it was. New answers, comments, and votes are closed.