Changing lighting but client-sided

I will keep my writing short, I’m trying to change lighting properties client-sided when player touches the parent. (part that the script is in it)
Server sided code works perfectly but I need to know how can I turn this scripts into a client-sided script?
My code:

    local light = game.Lighting
    script.Parent.Touched:Connect(function(part)
    	local humanoid = part.Parent:FindFirstChild("Humanoid")
    	if humanoid then
    		light.FogEnd = 100000
    		
    		light.FogStart = 0
    		
    		light.TimeOfDay = 14.5
    		
    		light.Brightness = 2
    		
    		light.FogColor = Color3.fromRGB(0,0,0)
    		
    		light.Ambient = Color3.fromRGB(165,165,165)
    		light.OutdoorAmbient = Color3.fromRGB(165,165,165)
    	end
    end)

You can just suggest me a method or just s e n d t h e w h o l e c o d e

3 Likes

Your script wouldn’t change that much when changing into a localscript, just remember localscripts does not run in workspace.

1 Like

You can use a RemoteEvent, fire it to the client and make the changes there.

1 Like

LocalScripts can’t run in the workspace, only in places like StarterPlayerScripts or StarterGui.

You’ll need to store your part as a variable like this: local myPart = workspace.my.directory.

1 Like

You would probably want to, make a remote event in replicated storage, and fire the client through the server, with :FireServer() in a server script in Server Script Service

And take the event on the client side, by:
.OnClientEvent in a local script in StarterGUI

And connect a function to it, and then change the lighting however you wish.

1 Like

Make a localscript in startergui and define the part as the location in workspace

1 Like

aa ok I changed the code but didn’t work

local light = game.Lighting
local part = game.Workspace.Part
part.Touched:Connect(function(touchpart)
	local humanoid = touchpart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		light.FogEnd = 10000 --default 10000

		light.FogStart = 0 --default 0

		light.TimeOfDay = 12 --default 12

		light.Brightness = 2 --default 2

		light.FogColor = Color3.fromRGB(165,165,165) --default 165,165,165

		light.Ambient = Color3.fromRGB(165,165,165) --default 165,165,165
		light.OutdoorAmbient = Color3.fromRGB(165,165,165) --default 165,165
	end
end)

Strange, your Humanoid may be nil.

Try adding random prints everywhere so you can debug?

1 Like

Script can sense if player touches the part so the problem is that the changes are server sided.

Just realized It won’t work since Roblox removed filtering enabled property.
I have to use remote events WHICH TAKES TIME