#making an oop character module thingy (solved)
1 messages · Page 1 of 1 (latest)
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
this didnt help
show us the code then
I made a typo lol, fixed it
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
you're doing the 2nd thing from my example, the wrong way
oh nvm you called it on LocalPlayer
any errors
yeah
what're they
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
ill see if this works
gimme a sec
the errors are gone which is a good start
but it isnt printing anything in output
which one
is this script a server script or local script
no
just do this;
local Player = Players.LocalPlayer
local LocalPlayer = PlayerClient.new(Player)
alrighty
imo though I don't entirely see the point of having your own class for the player & character but you do you
i wanted to restructure my entire game to use module scripts
all of my pre-existing systems didnt tie together nicely
alri, did that fix the issue btw
np