How to make it so it doesn't break when i die/reset?

Hello, i’am having the issue on this:

local D = game.ReplicatedStorage:WaitForChild("Day")
local N = game.ReplicatedStorage:WaitForChild("Night")

local Day = true

game.Players.PlayerAdded:Connect(function(plr)
	plr.PlayerGui:WaitForChild("ScreenGui").Menu.DayOrNightButton.MouseButton1Click:Connect(function()
		Day = not Day
		if Day == false then
			N:FireClient(plr)
		else
	 		D:FireClient(plr)
		end	
	end)	
end)

What i want is that the script doesn’t break when i reset. I will explain for you.

I’am using remote events to make the game day and night, i have this script in ServerScriptService, and other script(LocalScript) in StarterPlayerScripts, when i click an button(Gui button), it makes it day or night, but whenever i reset, it just breaks, how do i fix this?

I’m not entirely sure if this is the problem, but there’s a property of ScreenGuis called ResetOnSpawn. Make sure that’s set to false and try again. If it ISN’T the problem, you’ll have to manually connect it every time someone spawns.

2 Likes

Nevermind, that was the issue.