Hello, I’m working on a class fighting game and I’m doing class selection at the moment and I wanted to know if the class the player is playing should be stored on the client?
Currently, my code when the player touches a part it asks the server if it can play as that class and after sanity checks if the player can in-fact be that class the client will add the class module to them which just stores functions for abilities that the input code uses.
for _,part in ipairs(CollectionService:GetTagged("ClassSelector")) do
part.Touched:Connect(function(part)
local touchedModel = part:FindFirstAncestorWhichIsA("Model")
if not touchedModel then return end
local player = Players:GetPlayerFromCharacter(touchedModel)
if not player then return end
if player ~= Players.LocalPlayer then return end
print("Hey server! I wanna play as this class :)")
ClassSelected:FireServer()
end)
end
ClassSelected.OnServerEvent:Connect(function(player)
-- Eventually, add sanity checks
print("Ok client you can play as this class")
ClassSelected:FireClient(player,"TestClass")
end)
function Player.new()
local self = setmetatable({},Player)
self.Class = nil
self.Input = Input.new(self)
ClassSelected.OnClientEvent:Connect(function(class)
self:SetClass(class)
end)
return self
end
function Player:SetClass(className)
if not className then return end
if Classes:FindFirstChild(className) then
local classModule = require(Classes[className])
self.Class = classModule.new()
end
end