How do I make a freezing mechanic?

I want to make a freezing mechanic when it hits night time. For example, if the clock time is 19. The user will see their screen turning blue, after a few seconds. lets say 10. the user will be damaged until they find a light source.

PS: I am not asking anyone to write a script for me or a whole module, I would like someone to explain how I could make something like this. I don’t have much coding experience but I would like if someone did explain how this worked.

Thanks in Advance!!

can you send me any sort of script so i can understand what you mean

Basically, This script is designed and it has three functions. The first function displays a GUI frame between 7 PM and 7 AM. The second function damages the player by 3% of their health every second when the GUI frame is visible. The third function regenerates the player’s health by 2% every second when they are near a light source and stops regeneration when they are not near a light source, instead damaging the player’s health by 3% every second.

The code I am about to post is basically like how I want it to work. i tested it multiple times and it does not work because of my lackluster coding skills

local guiFrame = game.StarterGui.FreezeGUI.FreezeFrame

-- Loop to check the clocktime every second
while true do

	-- Get the current clocktime
	local hour = game:GetService("Lighting").ClockTime * 24

	-- Check if the clocktime is between 7 PM and 7 AM
	if hour >= 19 or hour < 7 then
		-- Show the GUI frame
		guiFrame.Visible = true
		-- Hide the GUI frame
		guiFrame.Visible = false

local gui = game:GetService("StarterGui"):WaitForChild("FreezeGui")
local damagePercentage = 3 -- 3% damage

while true do
	if gui.Visible then
		-- If the GUI is visible, it damages the player
		local player = game:GetService("Players").LocalPlayer
		player.Character:TakeDamage(player.Character.Humanoid.MaxHealth * (damagePercentage / 100))
	wait(1) -- Wait for 1 second before checking again

local regenPercentage = 2 -- 2% health regen
local regenDelay = 1 -- Regen delay in seconds
local minDistance = 5 -- Minimum distance to light source to trigger regen
local lightSources = game:GetService("Workspace"):GetChildren()

while true do
	local player = game:GetService("Players").LocalPlayer
	local character = player.Character

	-- Check if the player is near a light source
	local nearestLight = nil
	local nearestDistance = math.huge
	for _, instance in ipairs(lightSources) do
		if instance:IsA("Light") then
			local distance = (instance.Position - character.HumanoidRootPart.Position).Magnitude
			if distance < nearestDistance then
				nearestLight = instance
				nearestDistance = distance

	if nearestLight and nearestDistance < minDistance then
		-- If the player is near a light source, stop damaging them and start regenerating health
		gui.Visible = false
		character.Humanoid.Health = math.min(character.Humanoid.Health + character.Humanoid.MaxHealth * (regenPercentage / 100) * regenDelay, character.Humanoid.MaxHealth)
		-- If the player is not near a light source, damage them and stop regenerating health
		gui.Visible = true
		character:TakeDamage(character.Humanoid.MaxHealth * (damagePercentage / 100) * regenDelay)


usee change event on lightning and check clock time, then use local scripts

alright thanks, will consider using it and ill see how it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.