I'm a small game creator i have a problem with Base Health in my TD game how to fix it? problem is: ServerScriptService.Main.Base:20: attempt to perform arithmetic (div) on nil Help pls
~~~~~~~~~~~~~~~~~ local serverstorage = game:GetService("ServerStorage")
local Bindables = serverstorage:WaitForChild("Bindables")
local UpdateHealthEvent = Bindables:WaitForChild("UpdateBaseHealth")
local GameOverEvent = Bindables:WaitForChild("GameOver")
local Base = {}
function Base.Setup(map, health) Base.Model = workspace.map.Base Base.CurrentHealth = health Base.MaxHealth = health Base.UpdateHealth() end
function Base.UpdateHealth(damage) if damage then Base.CurrentHealth -= damage end
local gui = workspace.map.Base.HealthGui local precent = Base.CurrentHealth / Base.MaxHealth gui.CurrentHealth.Size = UDim2.new(precent, 0, 0.5, 0) if Base.CurrentHealth <= 0 then GameOverEvent:Fire() print("gameover") gui.Title.Text = "Base:Destroyed " end gui.Title.Text = "Base: " .. Base.CurrentHealth .. "/" .. Base.MaxHealth
end
UpdateHealthEvent.Event:Connect(Base.UpdateHealth())
return Base ~~~~~~~~~~~~~~~~~i
"attempt to perform arithmetic (div) on nil" means you're trying to use the / (division) operator on something that is nil (has no value), and the only sign of division I see is on "Base.CurrentHealth / Base.MaxHealth".
Looking at your code you have a function Base.Setup that assigns values to both Base.CurrentHealth and Base.MaxHealth, but I don't see it mentioned anywhere in the code you specified, possibly the reason why your properties are nil.