Search code examples
mathluainstancerobloxluau

attempt to perform arithmetic (sub) on Instance and number -- roblox


local HumanoidTaxi = script.Parent.Ally
local TaxiB = script.Parent.Damage
local Taxi = script.Parent
local TweenService = game:GetService("TweenService")
local Debounce = false
local Places = game.Workspace.PlacesAlly

TaxiB.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Zombie") then
        if not Debounce then
            Debounce = true
            local EnemyHumanoid = hit.Parent:FindFirstChild("Zombie")
            EnemyHumanoid.Health = EnemyHumanoid.Health - 25 ----------- This line
            HumanoidTaxi.Health = HumanoidTaxi.Health - EnemyHumanoid.Health
            wait(2)
            Debounce = false
        end
    end
end)



HumanoidTaxi.Died:Connect(function()
    Taxi:Destroy()
end)

for Place=1, #Places:GetChildren() do
    HumanoidTaxi:MoveTo(Places[Place].Position)
    HumanoidTaxi.MoveToFinished:Wait()
end

on the line marked, it says the error in the title. I have this code on another same taxi and it works on that one but not this. I don't understand why it doesn't work. Please suggest why it doesn't work!

i have tried searching this problem up on google but none have anything to do with solving my problem.


Solution

  • Health is not a Lua number, it's a NumberValue

    https://create.roblox.com/docs/reference/engine/classes/NumberValue

    To get the Lua number, use Health.Value to read and set it.