Need help with night and day change button

so I’m making a button that change the night to day and day to night the button work but the problem is the picture rest if player die because i put it in a gui that rest on spawn (i can change it or move it to another gui) so i made this script so if player die the picture change but its only change in starter gui and don’t change in player gui

local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local leaderstats = player:WaitForChild("leaderstats")
local leaderstats2 = player:WaitForChild("leaderstats2")
local Score = leaderstats:WaitForChild("Score")
local BestScore = leaderstats:WaitForChild("BestScore")
local Dif = leaderstats2:WaitForChild("Dif")
Character.Humanoid.Died:connect(function()
player.PlayerGui.ScoreGui.ScoreButton.ScoreScript.Disabled = true
player.PlayerGui.ScoreGui.Enabled = false
Dif.Value = 2
	workspace.Obstacles:Destroy()
	local Obstacles = Instance.new("Folder")
	Obstacles.Name = "Obstacles"
	Obstacles.Parent = workspace
	
	if game.Lighting.ClockTime == 14 then
		game.StarterGui.StartGui.DayNightChanger.Image = "rbxassetid://7546458145"
		player.PlayerGui.StartGui.DayNightChanger.Image = "rbxassetid://7546458145"
	else
		if game.Lighting.ClockTime == 0 then
			game.StarterGui.StartGui.DayNightChanger.Image = "rbxassetid://7546428910"
			player.PlayerGui.StartGui.DayNightChanger.Image = "rbxassetid://7546428910"
		end
end
end)	

1 Like

Btw this is the part of the script that I’m talking about

If the player dies then it’ll reset the gui therefore the image. If you add a local script into the gui checking the time of day and then changing the image so it corresponds with the time of day it should work.

So if you put this in a local script as a child of the imagelabel/imagebutton

if game.Lighting.TimeOfDay >= “07:00:00” then
script.Parent.Image = “rbxassetid://7546458145”
else
script.Parent.Image = “rbxassetid://7546428910”
end

if game.Lighting.TimeOfDay >= “18:00:00” then
script.Parent.Image = “rbxassetid://7546428910”
else
script.Parent.Image = “rbxassetid://7546458145”
end

I’m not making a night and day change with time I made a button if you click on it its be night and if you click on it again its be day

What that is doing is between 18:00:00 and 07:00:00 it is showing the night image and between 07:00:00 and 18:00:00 is showing the day image.

this is my button script

`local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if game.Lighting.ClockTime == 14 then
		game.Lighting.ClockTime = 0
		script.Parent.Image = "rbxassetid://7546428910"
		player.PlayerGui.StartGui.PlayButton.TextColor3 = Color3.new(1, 1, 1)
		player.PlayerGui.StartGui.BestScoreButton.TextColor3 = Color3.new(1, 1, 1)
		player.PlayerGui.StartGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
		player.PlayerGui.ScoreGui.ScoreButton.TextColor3 = Color3.new(1, 1, 1)	
	else
	if game.Lighting.ClockTime == 0 then
		game.Lighting.ClockTime = 14
		script.Parent.Image = "rbxassetid://7546458145"
		player.PlayerGui.StartGui.PlayButton.TextColor3 = Color3.new(0, 0, 0)
		player.PlayerGui.StartGui.BestScoreButton.TextColor3 = Color3.new(0, 0, 0)
		player.PlayerGui.StartGui.TextLabel.TextColor3 = Color3.new(0, 0, 0)
		player.PlayerGui.ScoreGui.ScoreButton.TextColor3 = Color3.new(0, 0, 0)	
	end
end
end)

i hope you understand now

1 Like

the problem is when the player die the gui rest but i cant make it dont rest beacuse there is something in the gui must be rest if player die

Yep I’m just working on a solution now!

1 Like

Do you want this to change the lighting globally for all players ingame or just the local player?

1 Like

for one player and the game is for one player so only one player in the server

1 Like

Did you found a solve ? (3 0 characters)

1 Like

Put this in a localscript under the button

if game.Players.LocalPlayer:FindFirstChild("Value") == nil then
	
	Instance.new("BoolValue").Parent = game.Players.LocalPlayer
	game.Players.LocalPlayer.Value.Name = "DayNightValue"
end

local Image = script.Parent.Parent.Image
local Day = "rbxassetid://7546458145"
local Night = "rbxassetid://7546428910"
local BoolValue = game.Players.LocalPlayer.DayNightValue
local Lighting = game.Lighting

if BoolValue.Value == false then
	Image.Image = Day
else	
	Image.Image = Night
end

script.Parent.MouseButton1Click:Connect(function()
	if BoolValue.Value == false then
		Lighting.TimeOfDay = "00:00:00"
		Image.Image = Night 
		BoolValue.Value = true
	else
		Lighting.TimeOfDay = "14:00:00"
			Image.Image = Day
			BoolValue.Value = false
	end
	end)
1 Like

thats work but you froget to change the text colours of these

to white if its night

player.PlayerGui.StartGui.PlayButton.TextColor3 = Color3.new(1, 1, 1)
		player.PlayerGui.StartGui.BestScoreButton.TextColor3 = Color3.new(1, 1, 1)
		player.PlayerGui.StartGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
		player.PlayerGui.ScoreGui.ScoreButton.TextColor3 = Color3.new(1, 1, 1)	

and to black if its day

player.PlayerGui.StartGui.PlayButton.TextColor3 = Color3.new(0, 0, 0)
		player.PlayerGui.StartGui.BestScoreButton.TextColor3 = Color3.new(0, 0, 0)
		player.PlayerGui.StartGui.TextLabel.TextColor3 = Color3.new(0, 0, 0)
		player.PlayerGui.ScoreGui.ScoreButton.TextColor3 = Color3.new(0, 0, 0)	

sorry but i dont know how to edit it

Is this in another Gui or is all this based in the StartGui?

all in StartGui and one in ScoreGui

Would it be possible to have a screenshot of the layout of these guis eg.

image

Screenshot 2021-09-24 022737

1 Like

if game.Players.LocalPlayer:FindFirstChild("Value") == nil then
	
	Instance.new("BoolValue").Parent = game.Players.LocalPlayer
	game.Players.LocalPlayer.Value.Name = "DayNightValue"
end

local Image = script.Parent.Parent.Image
local Day = "rbxassetid://7546458145"
local Night = "rbxassetid://7546428910"
local DayColor = Color3.new(1,1,1)
local NightColor = Color3.new(0,0,0)
local BoolValue = game.Players.LocalPlayer.DayNightValue
local Lighting = game.Lighting
local StartGui = game.Players.LocalPlayer.PlayerGui.StartGui
local ScoreGui = game.Players.LocalPlayer.PlayerGui.ScoreGui


if BoolValue.Value == false then
	Image.Image = Day
	ScoreGui.PlayButton.TextColor3 = DayColor
	ScoreGui.TextLabel.TextColor3 = DayColor
	ScoreGui.BestScoreButton.TextColor3 = DayColor
	StartGui.ScoreButton = DayColor
else	
	Image.Image = Night
	ScoreGui.PlayButton.TextColor3 = NightColor
	ScoreGui.TextLabel.TextColor3 = NightColor
	ScoreGui.BestScoreButton.TextColor3 = NightColor
	StartGui.ScoreButton = NightColor
end

script.Parent.MouseButton1Click:Connect(function()
	if BoolValue.Value == false then
		Lighting.TimeOfDay = "00:00:00"
		Image.Image = Night 
		ScoreGui.PlayButton.TextColor3 = NightColor
		ScoreGui.TextLabel.TextColor3 = NightColor
		ScoreGui.BestScoreButton.TextColor3 = NightColor
		StartGui.ScoreButton = NightColor
		BoolValue.Value = true
	else
		Lighting.TimeOfDay = "14:00:00"
		Image.Image = Day
		ScoreGui.PlayButton.TextColor3 = DayColor
		ScoreGui.TextLabel.TextColor3 = DayColor
		ScoreGui.BestScoreButton.TextColor3 = DayColor
		StartGui.ScoreButton = DayColor
			BoolValue.Value = false
	end
	end)
2 Likes

now only the score become white in night and the other still black sorry for annoyance