I have this script that instantly kills the player if the “RedLight” Text label is visible however i want someone to help me make an adjustment so that players have 1 second to stop, so AFTER the red light has been visible for 1 second THEN it should kill whoever moves (walks) /please help
Script:
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
checkPlayerMovementInFireArea()
end
end)
if redLightVisible then
if redLightStartTime == 0 then
redLightStartTime = tick()
elseif tick() - redLightStartTime >= 1 and humanoid.MoveDirection.Magnitude > 0 then
humanoid.Health = 0
end
end
Add a wait() before the if statement checking for movement because it already checks instantly then kills automatically after 2 seconds. It just delays their death not the check for their movement itself.
One recommendation is to disconnect the RunService function in the function “checkPlayerMovementInFireArea()” once its not needed since the function could be called again creating more and more unneccassary function calling and creating lag, unless if you want to keep the runservice function to keep firing (I have no idea what you want to do with it, but this is just a suggestion if you don’t want that kind of functionality)
And for your question I would put a task.wait(1) before the function checkPlayerMovementInFireArea(),
redLightStatusEvent.OnServerEvent:Connect(function(_, isVisible)
redLightVisible = isVisible
if redLightVisible then
task.wait(1) -- Waits one second before firing function
checkPlayerMovementInFireArea()
end
end)
This will wait 1 second before calling the function which checks for player movement after the red light has been visible.
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
local redLightStartTime = 0 -- Time when the red light becomes visible
-- 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
local playerMoving = humanoid.MoveDirection.Magnitude > 0
-- Check if the player is within the FireArea and the red light is visible
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
redLightVisible then
-- Wait 1 second after the red light is visible
if tick() - redLightStartTime >= 1 then
-- If the player is moving after 1 second, kill them
if playerMoving then
humanoid.Health = 0
end
end
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
redLightStartTime = tick() -- Record the time when red light is visible
checkPlayerMovementInFireArea()
end
end)
redLightStartTime: This variable tracks the time when the red light becomes visible using tick() (which returns the current time in seconds).
1-second delay: We check if 1 second has passed since the red light became visible (tick() - redLightStartTime >= 1).
Movement Check: If the player is moving within the fire area after 1 second, they are killed.
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 and when it was activated
local redLightVisible = false
local redLightStartTime = 0 -- Time when the red light becomes visible
-- Function to check player movement in FireArea
local function checkPlayerMovement()
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
local playerMoving = humanoid.MoveDirection.Magnitude > 0
-- Check if the player is within the FireArea and the red light is visible
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
redLightVisible then
-- Wait 1 second after the red light becomes visible
if tick() - redLightStartTime >= 1 then
-- If the player is moving after 1 second, kill them
if playerMoving then
humanoid.Health = 0
end
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
redLightStartTime = tick() -- Record the time when red light is visible
end
end)
-- Continuously check player movement on every frame
game:GetService("RunService").Heartbeat:Connect(checkPlayerMovement)
i can’t say exactly cuz i don’t see it and other stuff, other scripts maybe or not correct stuff in some services or guis for instance, and I don’t what you want do exactly with this script for gameplay (how it must looks)
so sorry