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

Why isn't the time changing properly?

Asked by
2_MMZ 1059 Moderation Voter
2 years ago

I'm helping my friend make a FNaF horror game, and I have the day/night cycle scripted, however, it doesn't work properly. Sure, it'll work in studio just fine, but when multiple players are on the game, the time will either be stuck at "12:00", or just be offset.

Here are the scripts I have.

Regular script in workspace

local remEvent = game.ReplicatedStorage:WaitForChild("changingtime")
local remEvent2 = game.ReplicatedStorage:WaitForChild("fixingtime")
wait(5) -- Waited 5 seconds for clients to pick it up
remEvent:FireAllClients()
remEvent2:FireAllClients()
wait()
script.Disabled = true

LocalScript in StarterGUI that handles the events

local remEvent2 = game.ReplicatedStorage:WaitForChild("fixingtime")

remEvent2.OnClientEvent:Connect(function()
    script.Parent.fixer.Disabled = false
    script.Parent.LocalScript.Disabled = false
end)

LocalScript in StarterGUI that plays the sound upon joining, (happens once i think)

print("Running time fixer.")
wait(0.2)
print("Fixed time. -2_MMZ")
game.Workspace.Sounds.FNAF6AM:Play()
game.Workspace.Sounds.Day:Play()
game.Workspace.Sounds.Day.Looped = true
script.Parent.Time2.Text = "Daytime"
script.Parent.Time.Text = "6:00 AM"

LocalScript in StarterGUI that handles the time and GUI text

    while wait(1) do
        game.Lighting.ClockTime += 0.02
        print("Changed time.")
        if game.Lighting.ClockTime == 0 then
            script.Parent.Time.Text = "12:00 AM"
            script.Parent.Time2.Text = "Nightshift"
            game.Workspace.Sounds.Night:Play()
            game.Workspace.Sounds.Night.Looped = true
            game.Workspace.Sounds.Day:Stop()
            game.Workspace.Sounds.Day.Looped = false
            game.Workspace.Sounds.hauntedSOULS:Stop()
        game.Workspace.Sounds.hauntedSOULS.Looped = false
        game.Workspace.DeezBuildingLights.Light17.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light18.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light19.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light20.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light21.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light22.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light23.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light24.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light25.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light26.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light27.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light28.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light29.SurfaceLight.Brightness = 0
        game.Workspace.DeezBuildingLights.Light30.SurfaceLight.Brightness = 0
        end

        if game.Lighting.ClockTime == 1 then
            script.Parent.Time.Text = "1:00 AM"
            script.Parent.Time2.Text = "Nightshift"
        end

        if game.Lighting.ClockTime == 2 then
            script.Parent.Time.Text = "2:00 AM"
            script.Parent.Time2.Text = "Nightshift"
        end

        if game.Lighting.ClockTime == 3 then
            script.Parent.Time.Text = "3:00 AM"
            script.Parent.Time2.Text = "Nightshift"
        end

        if game.Lighting.ClockTime == 4 then
            script.Parent.Time.Text = "4:00 AM"
            script.Parent.Time2.Text = "Nightshift"
        end

        if game.Lighting.ClockTime == 5 then
            script.Parent.Time.Text = "5:00 AM"
            script.Parent.Time2.Text = "Nightshift"
        end

        if game.Lighting.ClockTime == 6 then
            script.Parent.Time.Text = "6:00 AM"
            game.Workspace.Sounds.FNAF6AM:Play()
            script.Parent.Time2.Text = "Daytime"
            game.Workspace.Sounds.Night:Stop()
            game.Workspace.Sounds.Night.Looped = false
            game.Workspace.Sounds.Day:Play()
            game.Workspace.Sounds.Day.Looped = true
            game.Workspace.Sounds.hauntedSOULS:Stop()
        game.Workspace.Sounds.hauntedSOULS.Looped = false
        game.Workspace.DeezBuildingLights.Light17.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light18.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light19.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light20.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light21.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light22.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light23.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light24.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light25.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light26.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light27.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light28.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light29.SurfaceLight.Brightness = 2
        game.Workspace.DeezBuildingLights.Light30.SurfaceLight.Brightness = 2
        end

        if game.Lighting.ClockTime == 7 then
            script.Parent.Time.Text = "7:00 AM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 8 then
            script.Parent.Time.Text = "8:00 AM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 9 then
            script.Parent.Time.Text = "9:00 AM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 10 then
            script.Parent.Time.Text = "10:00 AM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 11 then
            script.Parent.Time.Text = "11:00 AM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 12 then
            script.Parent.Time.Text = "12:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 13 then
            script.Parent.Time.Text = "1:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 14 then
            script.Parent.Time.Text = "2:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end

        if game.Lighting.ClockTime == 15 then
            script.Parent.Time.Text = "3:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end
        if game.Lighting.ClockTime == 16 then
            script.Parent.Time.Text = "4:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end
        if game.Lighting.ClockTime == 17 then
            script.Parent.Time.Text = "5:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end
        if game.Lighting.ClockTime == 18 then
            script.Parent.Time.Text = "6:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end
        if game.Lighting.ClockTime == 19 then
            script.Parent.Time.Text = "7:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end
        if game.Lighting.ClockTime == 20 then
            script.Parent.Time.Text = "8:00 PM"
            script.Parent.Time2.Text = "Daytime"
        end
        if game.Lighting.ClockTime == 21 then
            script.Parent.Time.Text = "9:00 PM"
            script.Parent.Time2.Text = "Closing Time"
            game.Workspace.Sounds.hauntedSOULS:Play()
            game.Workspace.Sounds.hauntedSOULS.Looped = true
            game.Workspace.Sounds.Day:Stop()
            game.Workspace.Sounds.Day.Looped = false
            game.Workspace.Sounds.Night:Stop()
        game.Workspace.Sounds.Night.Looped = false
        game.Workspace.DeezBuildingLights.Light17.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light18.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light19.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light20.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light21.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light22.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light23.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light24.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light25.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light26.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light27.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light28.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light29.SurfaceLight.Brightness = 0.1
        game.Workspace.DeezBuildingLights.Light30.SurfaceLight.Brightness = 0.1
        end
        if game.Lighting.ClockTime == 22 then
            script.Parent.Time.Text = "10:00 PM"
            script.Parent.Time2.Text = "Closing Time"
        end
        if game.Lighting.ClockTime == 23 then
            script.Parent.Time.Text = "11:00 PM"
            script.Parent.Time2.Text = "Closing Time"
        end
    end

I'm very confused, if anyone can help me with this, I would be super grateful! ANY working answer is appreciated!

0
is it the clocktime or the label that doesn't work- NGC4637 602 — 2y
0
Both 2_MMZ 1059 — 2y
0
o NGC4637 602 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

When I made a time system, I put a few int values in replicatedStorage. Use a server script to change it, then access the value from a local script. This means they will all be synced up and no one will be left out.

Also try changing the light levels from a server script, it is unnecessary to change it from everyone's local scripts

(in answer to your original question, I don't think you initiate the script for new players, so if someone has bad internet and it takes more than 5 seconds to load, they won't get the message to start the time)

Ad

Answer this question