Hi! So, I wanted to know, how can I make it so that it’s night/day only for the person who clicked a button. Basically, I wanted to add a settings menu with an option to make it night or day. I know how to make a day/night cycle and how to set the time, but how would I do it for that specific player? Like, if one player tapped the button to set it to night, but another set it to day, would it even be possible? I’ve seen other games with this feature so I know that its possible but I just can’t figure out how. Any help would be greatly appreciated. Thank you!
Just put a LocalScript in the button, and do whatever you want with it.
Just put a localscript in the button and then put that script.
Hello. I would use the PlayerGui.
Ok, so if I put a local script, it will only do it for the player who clicked the button? So basically, in the script, I just set the time to night/day. If possible, could you provide a small script, but I understand if you can’t. Thank you!
Since it’s a local script it’ll be local, so only the local player will have that change.
Thats why it’s called a “LocalScript”
LocalScript:
script.Parent.MouseButton1Down:Connect(function()
game.Lighting.ClockTime = 0
end)
Click the link below to see where LocalScripts work:
You should try refering the day, night and the PlayerGui inside what I said there is Player, only the Player can see it so, and then you would with the PlayerGui set the time.
Oh so, the exact same as how I would do it in the Server script service, just inside a local script. Thanks for clarifying that!
Thank you @achdef , @foodislife345678 , and @DevCramp, this solved my issue! You all gave the same answer, but I’ll mark @DevCramp 's one as the solution because he gave it first!
ServerScriptService can’t take LocalScripts. That’s why it is called “ServerScriptService”
Click the link below to see where LocalScripts work:
Yes, I know that don’t worry. I will put the script inside of the button itself. Thanks!
If you need futher help you are welcome creating a new post!
local button = script.Parent
local day = true
button.MouseButton1Click:Connect(function()
day = not day
if day == true then
game.Lighting.ClockTime = 0
--other lighting stuff to make it better
else
game.Lighting.ClockTime = 14
--opposite of the lighting stuff for night
end
end)
Thank you so much, it really helped!
--LocalScript--
local Lighting = game:GetService("Lighting")
local __Args__ = {
__Clickable__ = script.Parent, -- Choose
__Active__ = true,
__Night__ = 0,
__Day__ = 14,
}
__Args__[1].MouseButton1Down:Connect(function()
if __Args__[2] then
__Args__[2] = false
Lighting.ClockTime = __Args__[3]
end
if __Args__[2] ~= true then
__Args__[2] = true
Lighting.ClockTime = __Args__[4]
end
end)