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)
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.
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)