Hello, So I’m making a local script that is supposed to slow the player down if damage is take. Basically, the method is to check every frame the player’s health, and if it’s less than 70, then they are supposed to slow the player down. Here is my code:
-- Services
local RunService = game:GetService("RunService")
-- Variables
local Player = script.Parent
local Humanoid = Player.Humanoid
local Health = Humanoid.Health
local Speed = Humanoid.WalkSpeed
-- Tables
local HealthTable = {
100 == 0,
85 == 3.5,
70 == 5,
55 == 7,
25 == 10,
10 == 15,
}
RunService.RenderStepped:Connect(function()
for i, v in pairs(HealthTable) do
if i <= Health and i < 70 then
Speed -= v
end
end
end)
And it prints out an error of: LocalScript:23: attempt to perform arithmetic (sub) on number and boolean
-- Services
local RunService = game:GetService("RunService")
-- Variables
local Player = script.Parent
local Humanoid = Player.Humanoid
-- Tables
local HealthTable = {
[10] = 15,
[25] = 10,
[55] = 7,
[70] = 5,
[85] = 3.5,
[100] = 0,
}
RunService.RenderStepped:Connect(function()
for i, v in pairs(HealthTable) do
if i <= Humanoid.Health and i < 70 then
Humanoid.WalkSpeed -= v
end
end
end)
-- Services
local RunService = game:GetService("RunService")
-- Variables
local Player = script.Parent
local Humanoid = Player.Humanoid
-- Tables
local HealthTable = {
[10] = 15,
[25] = 10,
[55] = 7,
[70] = 5,
[85] = 3.5,
[100] = 0,
}
Humanoid.HealthChanged:Connect(function()
if HealthTable[Humanoid.Health] then
Humanoid.WalkSpeed -= HealthTable[Humanoid.Health]
return
end
for i , v in pairs(HealthTable) do
if Humanoid.Health > HealthTable[i] and Humanoid.Health < HealthTable[i + 1] then
Humanoid.WalkSpeed -= HealthTable[i] --or i + 1, your choice here
end
end
end)