Hi!
I’m new to Luau and I’m attempting to extend type alias’ from a ReplicatedStorage module called PlayerClass. I want this class, so to speak, to be used by both the client and server, though with different functionality. (e.g. Server is data validation, and client is interactions/different effects).
But I’m running into issues extending the type alias PlayerClass
to its respective server and client type alias’.
The code runs as expected but I am getting a Type Pack error and a Type Error
I apologize I’m not sure if I’m explaining this best. Though this is my code:
--ServerSided Module Script that extends PlayerClass in RepStorage:
--Parented to Server Script in ServerScriptService
local PlayerClass = require(ReplicatedStorage.PlayerClass_Folder.PlayerClass)
local PlayerClassServer = {}
PlayerClassServer.__index = PlayerClassServer
setmetatable(PlayerClassServer, PlayerClass)
type PlayerClassServer = typeof(PlayerClass) & {
new: () -> PlayerClassServer,
isServerSided: boolean,
isServer: (self: PlayerClassServer) -> boolean,
}
function PlayerClassServer.new() : PlayerClassServer
local self = PlayerClass.new() :: PlayerClassServer
self.isServerSided = true
return setmetatable(self, PlayerClassServer)
end
function PlayerClassServer:isServer() : boolean
return self.isServerSided
end
return PlayerClassServer
This is my Server Script:
--!strict
--in server script service
--Roblox API--
local Players = game:GetService("Players")
local ServerPlayerClass = require(script.ServerSpecific)
type ServerPlayerClassType = typeof(ServerPlayerClass)
function onPlayerAdded(player)
local playerClass = ServerPlayerClass.new()
print(playerClass:getHealth())
print(playerClass:isServer())
end
Players.PlayerAdded:Connect(onPlayerAdded)
ServerScript:
ServerModule:
Thank you for your help!