How do I make it night for a player if they are high enough?

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.

Any help would be great! Thank you.

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.

  1. Make a local script

  2. If you know how to use tweenservice, use it, it will be smoother

  3. Check for the humanoidrootparts Y axis and if they are as high as u want them run the tween

Another option would be checking for alpha when going up and setting the client clocktime to that

3 Likes

Maybe this might work. :thinking:

local script:

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
2 Likes

How can you smooth the transition from day to night and night to day?

Try this…

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
1 Like

That doesn’t go back to day when I am lower than x studs

It just totally bugs out when I am lower and doesn’t go back

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

Here you go.

1 Like