I wanted to check If Player’s Health Is 0, If so then Dont trigger, if not Then trigger, but it doesnt seems to work
Script :
task.wait()
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local cooldown = false
local hum = Character:FindFirstChildWhichIsA("Humanoid")
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("UseFlashlight")
local Key = "F"
UIS.InputBegan:Connect(function(key, chatted)
if chatted then
return
end
if key.KeyCode == Enum.KeyCode[Key] then
print(hum.Health)
if not cooldown and Character and not hum.Health <= 0 then
remote:FireServer(key.KeyCode)
end
end
end)
if key.KeyCode == Enum.KeyCode[Key] then
print(hum.Health)
if not cooldown and Character then
if hum.Health >= 0 then
remote:FireServer(key.KeyCode)
end
end
end
end)
if key.KeyCode == Enum.KeyCode[Key] then
print(hum.Health)
if cooldown == false and Character then
if hum.Health <= 0 then
remote:FireServer(key.KeyCode)
end
end
end
end)
You’re confusing everyone, not gonna lie.
At first, you said:
Implying that if you’re dead, it shouldn’t work. Then you said the opposite:
which now implies you should be dead for the flashlight to activate.
Anyways, I tried fixing your code too. If it doesn’t work now… Well. I can’t really tell you much but good luck solving your issue.
UIS.InputBegan:Connect(function(key, chatted)
if chatted then
return
end
if key.KeyCode == Enum.KeyCode[Key] then
if hum.Health <= 0 then
warn("Humanoid is dead. Returning...")
end
if cooldown == false and Character ~= nil and hum.Health > 0 then
print("Successfully fired the remote!")
remote:FireServer(key.KeyCode)
end
end
end)