#why cant i call self

1 messages · Page 1 of 1 (latest)

turbid smelt
#

----------- TYPECHECKING -----------

--!strict
export type content_Ability = {

    name : string;
    cooldown : number;

    on_ability : () -> ();

}

local Ability = {}
Ability.__index = Ability

-------------- PLAYER --------------
local plr = game.Players.LocalPlayer

repeat task.wait() until plr.Character

local char = plr.Character
local hum : Humanoid = char.Humanoid
local root = char.HumanoidRootPart

-------------- CONTENT -------------

function Ability.New(args : content_Ability)
    
    local self = setmetatable({}, Ability)
    
    self.name = args.name
    self.cooldown = args.cooldown
    self.on_ability = args.on_ability
    
    if char:FindFirstChild(self.name) then warn("Already Equipped"); return end
    
    self.obj_ability = Instance.new("Tool")
    self.obj_ability.Name = self.name
    self.obj_ability.RequiresHandle = false
    
    hum:EquipTool(self.obj_ability)
    
    hum:UnequipTools()
    
    self.obj_ability.Equipped:Connect(function()
        
        Ability:Fire()
        
    end)
    
    return self
    
end

function Ability:Fire()
    
    self.on_ability()
    
    
    
end

return Ability

i js wanna call self.on_ability()

vapid nexusBOT
#

studio** You are now Level 13! **studio

hushed smelt
#

self is not definedbigbrain

#

nvm

#
    self.obj_ability.Equipped:Connect(function()
        
        Ability:Fire()
        
    end)

here you are refering to the table Ability and not to the "current obj", I think to fix this you just do self:Fire() @turbid smelt

turbid smelt
#

i got it working now it was self:Fire()