Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my blocking script not work when damage is inflicted?

Asked by
Cikeruw 14
2 years ago

for some reason my blocking script does not work, it makes the humanoids health infinite and it dies when 100 damage is inflicted.

local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")

local sprintSpeed = 30 
local walkSpeed = 16 

local player = players.LocalPlayer

local function beginSprint(input, gameProcessed)
    if not gameProcessed then        
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.F then 
                player.Character.Humanoid.MaxHealth = math.huge
                player.Character.Humanoid.Health = math.huge
            end
        end
    end
end

local function endSprint(input, gameProcessed)
    if not gameProcessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.F then
                player.Character.Humanoid.MaxHealth = 100
                player.Character.Humanoid.Health = 100
            end
        end
    end
end

userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)

1 answer

Log in to vote
0
Answered by 2 years ago

I think this will work:

local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")

local sprintSpeed = 30 
local walkSpeed = 16 

local player = players.LocalPlayer

local function beginSprint(input, gameProcessed)
    if not gameProcessed then        
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.F then 
                player.Character.Humanoid.MaxHealth = math.huge
                player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
            end
        end
    end
end

local function endSprint(input, gameProcessed)
    if not gameProcessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.F then
                player.Character.Humanoid.MaxHealth = 100
                player.Character.Humanoid.Health = 100
            end
        end
    end
end

userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)
Ad

Answer this question