ReplicatedStorage.Events.RED.OnServerEvent:Connect(function(plr)
RGLPart.Color = Color3.fromRGB(255, 0, 0)
ReplicatedStorage.Events.RED:FireAllClients()
db = true
task.wait(1) -- This
RunService.Heartbeat:Connect(function()
for Index, Player in ipairs(Players:GetPlayers()) do
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character.Humanoid or Character:WaitForChild("Humanoid")
if db == true then
if Player.Team == game.Teams.Player then
if touched == true then
if Humanoid.MoveDirection.Magnitude > 0 and Humanoid.Health > 0 then
Humanoid.Health = 0
end
else
print("Player not in game.")
end
else
print("Player not detected.")
end
else
break
end
end
end)
end)
So when the light turns red there's a one second delay before it kills just so that the players can have time to react but it only works once and kills instantly the next time.
I'm pretty new to scripting so I might've made a basic mistake, thanks if you decide to help me out.