#making an oop character module thingy (solved)

1 messages · Page 1 of 1 (latest)

misty remnant
#

You need to put something inside ()

sand sigil
#

did you call instantiate it before trying to call that method

#

what I mean is

local client = CharacterClient.new(Player)
local name = client:GetName()

-- vs

local client = CharacterClient.new(Player)
local name = CharacterClient:GetName()
#

first one will produce the expected outcome

sand sigil
#

show us the code then

long aspen
#

i fixed the typo earlier

#

im still doing something wrong though

#
-- Services --

local Players = game:GetService("Players")
local Modules = game.ReplicatedFirst.Player.Modules

-- Modules --

local CharacterClient = require(Modules.CharacterClient)
local PlayerClient = require(Modules.PlayerClient)

Players.PlayerAdded:Connect(function(Player)
    Players.LocalPlayer.CharacterAppearanceLoaded:Connect(function(Character)
    
        local LocalPlayer = PlayerClient.new(Player)
        local LocalCharacter = CharacterClient.new(Character)
        
        print(LocalPlayer:GetName())
        
    end)
end)
#

client script

#
local PlayerClient = {}
PlayerClient.__index = PlayerClient

function PlayerClient.new(Player)
    
    local self = setmetatable({},PlayerClient)
    self.Player = Player;
    self.UserID = Player.UserId;
    self.Name = Player.Name;
    self.DisplayName = Player.DisplayName;
    self.AccountAge = Player.AccountAge
    
    return self
end

function PlayerClient:GetUserID()
    
    return self.UserID
end

function PlayerClient:GetName()
    
    return self.Name
end

function PlayerClient:GetDisplayName()
    
    return self.DisplayName
end

function PlayerClient:GetAccountAge()
    
    return self.AccountAge
end

return PlayerClient.new()
#

player module

#
local CharacterClient = {}
CharacterClient.__index = CharacterClient

function CharacterClient.new(CharacterInstance)

    local self = setmetatable({},CharacterClient)    
    self.CharacterInstance = CharacterInstance;
    self.Character = CharacterInstance

    return self
end

return CharacterClient.new()
#

character module

#

this is everything there is to it

sand sigil
#

you're doing the 2nd thing from my example, the wrong way

#

oh nvm you called it on LocalPlayer

#

any errors

long aspen
#

yeah

sand sigil
#

what're they

long aspen
sand sigil
#

what's on lines 8 and 36

#

oh I see the issue now

#

you're returning CharacterClient.new() and PlayerClient.new()

#

just return PlayerClient and CharacterClient

long aspen
#

ill see if this works

#

gimme a sec

#

the errors are gone which is a good start

#

but it isnt printing anything in output

sand sigil
#

which one

sand sigil
long aspen
#

local script

#

in starter player scripts

sand sigil
#

Players.PlayerAdded will fire but it won't include the local player

#

just remove that

long aspen
#

i need it as a parameter though dont i?

#

local LocalPlayer = PlayerClient.new(Player)

sand sigil
#

no

#

just do this;

#
local Player = Players.LocalPlayer
local LocalPlayer = PlayerClient.new(Player)
long aspen
#

alrighty

sand sigil
#

imo though I don't entirely see the point of having your own class for the player & character but you do you

long aspen
#

i wanted to restructure my entire game to use module scripts

#

all of my pre-existing systems didnt tie together nicely

sand sigil
#

alri, did that fix the issue btw

long aspen
#

i had to change one more thing

#

but it works now

#

thank you very much

sand sigil
#

np