Not found in table 'Base'

not found in table ‘Base’

local Base = {}

function Base.Setup(Map, Health)
	Base.Model = Map:WaitForChild("Base")
	Base.CurrentHealth = Health
	Base.MaxHealth = Health
	
	Base.UpdateHealth()
end

function Base.UpdateHealth(Damage)
	if Damage then
		Base.CurrentHealth -= Damage
	end
	
	local Gui = Base.Model.HealthGui
	local Percent = Base.CurrentHealth / Base.MaxHealth
	
	Gui.CurrentHealth.Size = UDim2.new(Percent, 0, 0.5, 0)
	
	if Base.CurrentHealth <= 0 then
		GameOver:Fire()
		
		Gui.Title.Text = "Base: DESTROYED"
	else
		Gui.Title.Text = "Base: " .. Base.CurrentHealth .. "/" .. Base.MaxHealth
	end
end

return Base

Script Analysis error:

image

Because its all declared inside setup, try inserting them outside the function. I feel like your going for an oop approach here so:

local Base = {}
Base.__index = Base

function Base.new(Map, Health)
        local this = setmetatable({}, Base)
	this.Model = Map:WaitForChild("Base")
	this.CurrentHealth = Health
	this.MaxHealth = Health
	
	this:UpdateHealth()

        return this
end

function Base:UpdateHealth(Damage)
	if Damage then
		self.CurrentHealth -= Damage
	end
	
	local Gui = self.Model.HealthGui
	local Percent = self.CurrentHealth / self.MaxHealth
	
	Gui.CurrentHealth.Size = UDim2.new(Percent, 0, 0.5, 0)
	
	if self.CurrentHealth <= 0 then
		GameOver:Fire()
		
		Gui.Title.Text = "Base: DESTROYED"
	else
		Gui.Title.Text = "Base: " .. self.CurrentHealth .. "/" .. self.MaxHealth
	end
end

return Base

Now u can do

local base = Base.new(...)
base:UpdateHealth()

So can I just place the UpdateHealth() outside of the function?

The error still occurs when I tried writing your example. I just found this code for a tutorial video.

Dw abt the errors just run the script and make sure you call Setup before anything else.