Hi, I’m trying to make it so when the player is touching a block and presses the space key the player’s health gets set to 0, only if they press space and touching it. However nothing seems to happen and there are no errors in the output, I’ve looked on the devforum and other places but I found nothing and I’m just stuck on what to do.
local block = script.Parent
local humanoid
local function onTouch(otherPart)
local character = otherPart.Parent
humanoid = character:FindFirstChildWhichIsA("Humanoid")
end
local function onInput(input)
if input.KeyCode == Enum.KeyCode.Space and humanoid then
humanoid.Health = 0
end
end
block.Touched:Connect(onTouch)
game:GetService("UserInputService").InputBegan:Connect(onInput)
Any help would be grateful, thanks.