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

How do I make my Day/Night button change fog color?

Asked by
c4ots 12
1 year ago

The script works just fine on its own, but I need it to change fog color to black once it's set to night and then switch the fog color back to blue when it's day. I tried adding lighting.FogColor = [color] to it but then it breaks. Heres my time script for reference:

local lighting = game.Lighting

local btn = script.Parent

btn.MouseButton1Click:Connect(function()

if lighting.ClockTime == 15.5 then

    lighting.ClockTime = 21

    btn.Text = "Day"

    lighting.FogEnd = 250


else

    lighting.ClockTime = 15.5
    btn.Text = "Night"
    lighting.FogEnd = 1000000
end

end)

Please help and thank you!

1 answer

Log in to vote
0
Answered by 1 year ago

Explanation of a Roblox lighting toggle button script.

This code creates a button that changes the lighting in a Roblox game between day and night when clicked. When the button is clicked, the script checks the current ClockTime of the Lighting service. If it is equal to 15.5, the lighting is set to night mode and the button text is changed to "Night". If the ClockTime is not equal to 15.5, the lighting is set to day mode and the button text is changed to "Day".

local Lighting = game:GetService("Lighting")
local Button = script:FindFirstAncestorWhichIsA("GuiButton")

Button.MouseButton1Up:Connect(function(x, y)
    if Lighting.ClockTime == 15.5 then
        Lighting.ClockTime = 21
        Button.Text = "Day"
        Lighting.FogEnd = 250
        Lighting.FogColor = Color3.fromRGB(255, 255, 255)
    else
        Lighting.ClockTime = 15.5
        Button.Text = "Night"
        Lighting.FogEnd = 1000000
        Lighting.FogColor = Color3.fromRGB(0, 0, 0)
    end
end)

Retrieving Service Instances from the DataModel

It is generally safer and more reliable to use game:GetService("Service") to access service Instances in Roblox. This is the recommended approach in the Roblox documentation and by most experienced Roblox developers.

Ad

Answer this question