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.
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()
Put the code in StarterPlayerScripts and change script.Parent to the location of the part in workspace and game.Lighting to `game:GetService(“Lighting”)
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)