Hello, I’m trying to make a game about red light and green light, but I have a little problem.
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local function StartRedLightGreenLight()
local Enabled = false
task.spawn(function()
while true do
Enabled = false
ReplicatedStorage.UpdateUI:FireAllClients({"DownText", "Text", "Green Light"}, {"DownText", "TextColor3", Color3.fromRGB(77, 255, 57)})
task.wait(5)
ReplicatedStorage.UpdateUI:FireAllClients({"DownText", "Text", "Red Light"}, {"DownText", "TextColor3", Color3.fromRGB(255, 0, 0)})
task.wait(0.3)
Enabled = true
task.wait(5)
end
end)
while true do
if Enabled then
for _, player in pairs(Players:GetPlayers()) do
if player.Character then
local Humanoid = player.Character:FindFirstChild("Humanoid")
if Humanoid then
if Humanoid.MoveDirection.Magnitude > 0 then -- This never continues even if you are moving.
Humanoid.Health = Humanoid.MaxHealth
end
end
end
end
end
task.wait()
end
end
StartRedLightGreenLight()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local function StartRedLightGreenLight()
local Enabled = false
task.spawn(function()
while true do
Enabled = false
ReplicatedStorage.UpdateUI:FireAllClients({"DownText", "Text", "Green Light"}, {"DownText", "TextColor3", Color3.fromRGB(77, 255, 57)})
task.wait(5)
ReplicatedStorage.UpdateUI:FireAllClients({"DownText", "Text", "Red Light"}, {"DownText", "TextColor3", Color3.fromRGB(255, 0, 0)})
task.wait(0.3)
Enabled = true
task.wait(5)
end
end)
while wait() do
if Enabled then
for _, player in pairs(Players:GetPlayers()) do
local Character = player.Character
if Character then
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
if Humanoid.MoveDirection.Magnitude > 0 then
Humanoid.Health = Humanoid.MaxHealth
end
end
end
end
end
end
end
StartRedLightGreenLight()
Instead of using MoveDirection, why not use HumanoidStateTypes? You could check if they are Walking, Running or Jumping, or even Falling, that’s where the robot should kill them.
Hi, I tried to use that but the players don’t die. But I have added prints on that line that modifies the health of the player and prints it on the output, but does not kill the player even if they are moving.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local function StartRedLightGreenLight()
local Enabled = false
task.spawn(function()
while true do
Enabled = false
ReplicatedStorage.UpdateUI:FireAllClients({"DownText", "Text", "Green Light"}, {"DownText", "TextColor3", Color3.fromRGB(77, 255, 57)})
task.wait(5)
ReplicatedStorage.UpdateUI:FireAllClients({"DownText", "Text", "Red Light"}, {"DownText", "TextColor3", Color3.fromRGB(255, 0, 0)})
task.wait(0.3)
Enabled = true
task.wait(5)
end
end)
while wait() do
if Enabled then
for _, player in pairs(Players:GetPlayers()) do
local Character = player.Character
if Character then
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
if Humanoid:GetState() == Enum.HumanoidStateType.Running then
Humanoid.Health = Humanoid.MaxHealth
end
end
end
end
end
end
end
StartRedLightGreenLight()
Before the error use print(Humanoid.MoveDirection.Magnitude) to see why it isn’t working.
If that errors just trying printing Humanoid.MoveDirection. Tell me the result.