Player only lighting

So, I made a part and added a script. When a player touches the part, time of day changes.
Script:

function onTouch(onTouch)

game.Lighting.TimeOfDay = "12:00:00"

end

script.Parent.Touched:connect(onTouch)

I want this script to work for only touched player. I mean time changes for the touching player only. Like the touching player sees sky night, not touching player sees sky sunny.

You’d have to probably change the script into a localscript to have local changes

I already changed the script to local script but It did’nt work. It didn’t even changed the time

Try changing game.Lighting to game:GetService("Lighting")

Also, where is thsi script located?

LocalScripts can only detect the .Touched function if they are inside of the player meaning the LocalScript would need to be inside of the PlayerGui, StarterPlayer > StarterCharacterScripts
I think you can also put the LocalScript in StarterPlayer > StarterPLayerScripts but im not sure if it will work there

So simply put the LocalScript in one of the places I just listed and type a path to the part you want to detect when it’s touched so example: game.Workspace.LightingPart.Touched:Connect(function()

Child of the part that player will touch

Try putting the localscript inside of somewhere the Localscript will work in, which is one of these locations

  • The player’s backpack
  • StarterGui
  • StarterCharacterScripts
  • StarterPlayerScripts
  • ReplicatedFirst

Could you share the whole code?

function onTouch(onTouch)

game.Lighting.TimeOfDay = "12:00:00"

end

script.Parent.Touched:connect(onTouch)

Put the code in StarterPlayerScripts and change script.Parent to the location of the part in workspace and game.Lighting to `game:GetService(“Lighting”)

uhh… can you share the edited verison?..
I’m trying to learn so if you want please send

Basically, put the localscript in one of those 5 areas I mentioned above and change the code to this

local part = --Location if your part
local lighting = game:GetService("Lighting")

local function onTouch()
    lighting.TimeOfDay = "12:00:00"
end

part.Touched:Connect(onTouch)

You can’t detect if a part was touched, at least using this specific function, from the client, you would need to make a server script for it and fire for the client.

Eh, it doesn’t really matter unless you want all players to see the change.

Hypothetical Code (on the server)

local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")

local TouchPart = workspace.TouchPart

TouchPart.Touched:Connect(function(hitPart)
    local character = Players:GetPlayerFromCharacter(hitPart.Parent)
    if character then
        Lighting.ClockTime = 12
    end
end)

He said I want this script to work for only touched player. I mean time changes for the touching player only.