Hello, I am trying to make it so for a player it is night if they are high enough. I am trying to make something that if you click it launches you high then sends you down. It would just look cool if in the process it will become night.
If you alter the Lighting service from the client, it will affect only them. Try making a LocalScript where the player is trusted to handle it. You could either have them do their own logic for height, or the server does it and shoots a remote event when to start/stop the night effect.
local player = game.Players.LocalPlayer
local character = player.Character
local TimeOfDayToChange = 5
local HightToTurnDark = 50
while wait(0.1) do
if character and character:FindFirstChild("HumanoidRootPart") then
if character:FindFirstChild("HumanoidRootPart").Position.Y > HightToTurnDark then
game.Lighting.TimeOfDay = TimeOfDayToChange
end
else
character = player.Character
end
end
local player = game.Players.LocalPlayer
local character = player.Character
local TimeOfDayToChange = 5
local HightToTurnDark = 50
while wait(0.1) do
if character and character:FindFirstChild("HumanoidRootPart") then
if character:FindFirstChild("HumanoidRootPart").Position.Y > HightToTurnDark then
repeat game.Lighting.ClockTime -= 0.5 wait(0.1) until TimeOfDayToChange == game.Lighting.ClockTime
end
else
character = player.Character
end
end
local lighting = game:GetService("Lighting")
local tweens = game:GetService("TweenService")
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local tween
while true do
run.RenderStepped:Wait()
if hrp.Position.Y >= 50 then
if tween then
tween:Cancel()
end
tween = tweens:Create(lighting, TweenInfo.new(1.5, Enum.EasingStyle.Linear), {ClockTime = 0})
tween:Play()
else
if tween then
tween:Cancel()
end
tween = tweens:Create(lighting, TweenInfo.new(1.5, Enum.EasingStyle.Linear), {ClockTime = 12})
tween:Play()
end
end