Time Of Day not changing with touched part

Made a script that when you touch a part a bunch of different effects will happen
little bit of it.

what’s weird is that in studio it works at times but when I try to test in game I don’t get anything… it stays at time 17 daylight… where the script should change it to 18 which is sunset time.

local LocalPlayer = game:GetService('Players').LocalPlayer
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:wait()
local HumanoidRootPart = character:WaitForChild('HumanoidRootPart')
local PlayerGui = LocalPlayer.PlayerGui
local currentPlayingSong = nil
local CollectionService = game:GetService("CollectionService")

local bloom = game.Lighting.Bloom
local blur = game.Lighting.Blur
local ColorCorrection = game.Lighting.ColorCorrection
local SunRays = game.Lighting.SunRays
local Depth = game.Lighting.DepthOfField

LocalPlayer.Character.HumanoidRootPart.Touched:Connect(function(hit)
	if hit.Name == ("Effect0") then
		
		
		
		bloom.Intensity = 0.25
		bloom.Size = 20
		bloom.Threshold = 1

		blur.Size = 0

		ColorCorrection.Brightness = 0.05
		ColorCorrection.Contrast = 0.1
		ColorCorrection.Saturation = -0.2
		ColorCorrection.TintColor = Color3.fromRGB(255, 255, 255)

		SunRays.Intensity = .1
		SunRays.Spread = 1
		----------optional----------- add "--" to deactive lines
		game.Lighting.Brightness = 2.27
		game.Lighting.ShadowSoftness = 1
		game.Lighting.ClockTime = 18
		game.Lighting.FogColor = Color3.fromRGB(0,0,0)
		game.Lighting.FogStart = 200
		game.Lighting.FogEnd = 1000

if its working in studio and not in game are you sure you have published the game?

alssoooo instead of detecting everything the humanoid rootpart hits detect if the relevant parts touch the humanoid id say save a lot of checking

allssoooo the humanoid root part might not hit the relevant parts because it is in the center of the humanoid so if the part you are trying to touch is on the floor or sumn it wont work

yeah I know its published cause I make other changes as well, for some reason my other effects 1-9 work fine but one right under spawn doesn’t trigger time changes

nevermind sorry, I can figure it out the time changes back if I go to another effect and back but changes to wrong time… I think its just using default settings

well your code doesnt look wrong to me if everything else is firing properly however i will provide you with a better more efficient way to do it:
put this script into the part you want them to touch for the time to change it will check if a humaoid hit it (a person then change the time)

local Part = Script.Parent

Part.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		game.Lighting.ClockTime = 18
	end
end)
1 Like

how would this differ from the script I have above that touches the humanrootpart… and nvm the script doesn’t work even in studio… time won’t change even though the script looks fine to me as well

I believe @S0MBRX is correct with this. If the part is on the ground (and doesn’t reach the HumanoidRootPart – might I add is like a 2x2x1 part), then you would also want to check if the feet or legs touched the interactive part.

Also this might be the issue? I’m not sure what this is checking here?

It differs since it lets any body part touch the effect part instead of just the root part, so it has a 100% chance to work since it may not always hit the root part

1 Like

the hit cube is larger than the player being like 10x10x10
the thing that doesn’t make sense to me is half the effects will work
-blur
-bloom

but game lighting is causing all the issues

Understood! What I was saying was simply advice. :slight_smile:

Found this post about Server-Client Replication for the game.Lighting.

Now, I am not sure at all if this is your issue, but it is something to be aware of. Is your script a LocalScript or a (Server) Script?

1 Like

yeah that’s probably it. confusing since other properties in lighting work but not time of day etc…
It is a local script

Nevermind, I answered my own question by simply checking that the LocalPlayer variable was used. :laughing:

You would most likely need to use a server script for anything Lighting-related.

Let’s try this:

Create a RemoteEvent in game.ReplicatedStorage and name it “lightingEvent” (no quotes).
Code-wise:

-- Server Script

local lightingEvent = game.ReplicatedStorage:WaitForChild("lightingEvent")

Effect0.Touched:Connect(function(hit)
	if hit.Parent then -- to be safe
		if hit.Parent:FindFirstChild("Humanoid") then -- is a humanoid
			if game.Players:FindFirstChild(hit.Parent.Name) then -- is a Player
			
				
				local Player = game.Players[hit.Parent.Name]
				
				-- Fire some RemoveEvent here (to signial local handling)
				lightingEvent:FireClient(Player) -- signal that the player touched
				
			end
		end
	end
end)
-- Local Script

local lightingEvent = game.ReplicatedStorage:WaitForChild("lightingEvent")

function touchedLightingPart()

	-- do your local handling here

end

lightingEvent.OnClientEvent:Connect(touchedLightingPart)


In short, what this does is:

Server-side:
Handles your touch event AND makes sure that a living, Player touches your Effect0 part. If all is satisfied, it sends a signal to the touching Player’s client where you could handle your local handling (if needed – if not ignore the local side and remove the lightingEvent:FireClient(Player) line and ignore the event code).

Locally:
Handle any GUI updates or other LOCAL updates you might want to add.

edit:
I wanna mention that you can add any other code you had above (related to the lighting) here:

2 Likes

thank you! I wasn’t expecting to have to run a event just for a simple toggle but makes sense, I was going to change the script to not be local and just have it work client sided but I love to learn more about events anyways cheers!

1 Like

Yes, of course. Glad to help! Feel free to come back if it doesn’t work as intended (or message me, but it could be useful for others to post back here! :slight_smile: ).

Also bare in mind:
The RemoteEvent is used if you want to update client (like interface or something that ONLY affects the client).
You should very well be able to do what you had in mind with just the server script (once you add your lighting effects).

I just added the RemoteEvent because I noticed you had

included in the original code :slight_smile:
Cheers! Good luck.

1 Like