Help me add a detail to my script

Here let me send you the full script with the wait.

Adding tick() does not delay function calling, plus that script got rid of it so the function won’t be called, tick() could be implemented to the script however instead of creating ticks and complicating the script. task.wait(seconds) or wait(seconds) delays anyways since thats what these functions are for.

Here:

local fireArea = workspace.RedLightGreenLight.HitParts:FindFirstChild("FireArea")
local fireAreaSize = fireArea.Size / 2
local redLightStatusEvent = game.ReplicatedStorage:WaitForChild("RedLightStatus")

-- Variable to track if RedLight is visible
local redLightVisible = false

-- Function to check player movement in FireArea
local function checkPlayerMovementInFireArea()
	game:GetService("RunService").Heartbeat:Connect(function()
		for _, player in pairs(game:GetService("Players"):GetPlayers()) do
			local char = player.Character
			if char then
				local hrp = char:FindFirstChild("HumanoidRootPart")
				local humanoid = char:FindFirstChild("Humanoid")
				if hrp and humanoid then
					local min, max = fireArea.Position - fireAreaSize, fireArea.Position + fireAreaSize
					if hrp.Position.X >= min.X and hrp.Position.X <= max.X and
						hrp.Position.Y >= min.Y and hrp.Position.Y <= max.Y and
						hrp.Position.Z >= min.Z and hrp.Position.Z <= max.Z and
						humanoid.MoveDirection.Magnitude > 0 and redLightVisible then
						wait(2)  -- Wait for 2 seconds before killing
						humanoid.Health = 0
					end
				end
			end
		end
	end)
end

-- Listen for changes in RedLight status from the client
redLightStatusEvent.OnServerEvent:Connect(function(_, isVisible)
	redLightVisible = isVisible
	if redLightVisible then
        task.wait(1) -- Waits one second before firing the kill function, you can change the amount of seconds inside if you want more delay.
		checkPlayerMovementInFireArea()
	end
end)
1 Like