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

How can I make 2 scripts completely synced?

Asked by 3 years ago

I am working on a main menu system that contains multiple camera angles with each angle having different lighting effects(Depth of field, color correction, light rays). However, I am having issues with the timing of the scripts. Currently how it works is that the camera is not a local script, making every player share the same view on the main menu, every 10 seconds the camera teleports to a new location which is a different angle. I have timed it so the lighting script, which is a local script(so that players in-game won't be affected by the lighting) is almost exactly synced, (I used a remoteevent which fires causing the camera move script to work once the lighting starts). The problem that happens is that eventually, the lighting loses its sync with the camera movements, as well as when a player resets and is brought back to the menu it is entirely out of sync. I am looking for a solution to this issue but I am unsure how, I am not looking for code, just advice. Maybe if I change the placement of my scripts or if there is a way to combine them?

--camera movement server script located under a part in workspace

local part = script.Parent
game.ReplicatedStorage.LightingStarts.OnServerEvent:Connect(function(player)
    while true do
        part.Position = Vector3.new(-1257.005, -47.561, 781.581)
        part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(-60), 0)
        part.CFrame = part.CFrame * CFrame.Angles(math.rad(15), 0, 0)
        wait(10)
        part.Position = Vector3.new(-1461.755, -2.751, -733.411)
        part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(15), 0)
        part.CFrame = part.CFrame * CFrame.Angles(math.rad(75), 0, 0)
        wait(10)
        part.Position = Vector3.new(-1827.355, 50.249, -5662.611)
        part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(-60), 0)
        wait(10)
        part.Position = Vector3.new(-1339.683, 42.476, -1993.297)
        part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(120), 0)
        part.CFrame = part.CFrame * CFrame.Angles(math.rad(30), 0, 0)
        wait(10)
    end
end)

If there is a way I can combine these scripts while keeping the lighting to only players on the main menu, that would be great.

--local script located in replicated first under the main menu GUI (that gets copied once the game loads)

local DOF = game.Lighting.DepthOfField
local ColorCorrection = game.Lighting.ColorCorrection
local SunRays = game.Lighting.SunRays

wait()

game.ReplicatedStorage.LightingStarts:FireServer()

while true do
    DOF.FarIntensity = 0.5
    DOF.FocusDistance = 12
    DOF.InFocusRadius = 10
    DOF.NearIntensity = 0
    ColorCorrection.Contrast = 0.4
    ColorCorrection.Saturation = 0.5
    SunRays.Intensity = 0.3
    wait(10)
    DOF.FarIntensity = 0
    DOF.FocusDistance = 85
    DOF.InFocusRadius = 25
    DOF.NearIntensity = 0.5
    ColorCorrection.Contrast = 0.3
    ColorCorrection.Saturation = 0.2
    SunRays.Intensity = 0.7
    wait(10)
    DOF.FarIntensity = 0.3
    DOF.FocusDistance = 0
    DOF.InFocusRadius = 20
    DOF.NearIntensity = 1
    ColorCorrection.Contrast = 0.2
    ColorCorrection.Saturation = 0.1
    SunRays.Intensity = 0.4
    wait(10)
    DOF.FarIntensity = 1
    DOF.FocusDistance = 500
    DOF.InFocusRadius = 0
    DOF.NearIntensity = 1
    ColorCorrection.Contrast = -0.1
    ColorCorrection.Saturation = 0.5
    SunRays.Intensity = 0.9
    wait(10)
end

1 answer

Log in to vote
0
Answered by 3 years ago

If you mean making them run at the exact same time, you can't get them perfectly synced. There will be an almost unnoticeable delay (probably even unnoticeable) 24/7. The delay is probably in the milliseconds and shouldn't affect anything. The milliseconds delay can be from just having a lot of scripts run in the server at once or a line of a script doing a lot at once. You could have an event and have both scripts start running when it is fired, making them pretty much in sync, or you could have a script enable them without a wait() between. Otherwise, I'm not completely sure how you could make them any more in sync than that.

Ad

Answer this question