Team-Based characters

hi, ive been trying to create a team-based avatar system for my game, for the teams “Goblins” and “Knights”, ive tried a few tutorials, and looked on the dev forum, but ive found nothing that works,
ive tried something like this

if Player.Team == goblinTeam then
	Player.Character = goblinCharacter 
end

the character is changed, you can control it, BUT, the camera dosent follow the new character. im not that good at scripting.

Just do smth like:

local Players = game:GetService("Players")
local knightOutfit = ...path
local goblinOutfit = ...path

local function PlrAdded(Plr:Player):()
	local function TeamChange():()
		local Team = Plr.Team
		if Team.Name=="Goblin" then
			local char = goblinOutfit:Clone()
			char.Parent=workspace
			Plr.Character=char
		else--Knight
			local char = knightOutfit:Clone()
			char.Parent=workspace
			Plr.Character=char
		end

	end
	Plr:GetPropertyChangedSignal("Team"):Connect(TeamChange)
	TeamChange()
end
Players.PlayedAdded:Connect(PlrAdded)
for i,v in Players:GetPlayers() do
	PlrAdded(v)
end

Unless you’re writing this on mobile, please indent

i was writing it right in devforum
I dont need “fancy IDE” to write code :sunglasses:

1 Like

honestly thats fine but you should probably write your examples in studio first

I dont think you can apply the rig directly to the character, might be wrong, because so far for me that hasnt worked properly

Made this system myself, first gotta make it so that characterAutoLoads in playerService is off. Then make two folders in starterCharacterScripts, and call them Server and Client. To handle the server and client, when the game starts, load all the items from server into the player via server script. Do the same with client. That’s good for the loading.

As for what to put into server and client, make sure to also take a copy of the Animate default roblox script as well. The rest should just be normal scripts and stuff. Make sure to set the workspace.CurrentCamera.CameraSubject = character.Humanoid to fix the camera problem.

As for how to load the scripts, make one local script in starterPlayerScripts under starterPlayer and a server script in serverScriptService. Also make sure to create a remoteEvent. You should then call the remote event from the client whenever you want the player to be loaded and wait for a response using character = remoteEvent.OnClientEvent:Wait(). (Or you should use a remoteFunction, prob gonna be recommended by anyone else who sees this, they can show an example if they want.) Make sure the remoteEvent is placed in replicated storage as well. (Optional, just make sure both server and client can access it.)

Then you should use the server to clone a character and save it. After that, you should loop through starterCharacterScripts.Server:GetChildren() and clone the children onto the character. As for the client script, fire the remote event with the character that the server created to client. Once the client receives the character from the remote event, clone starterCharacterScripts.Client:GetChildren() onto the new character.

Be wary that it might bug when loading onto the character. I added a task.wait(5) to solve it as character:WaitForChild(“Humanoid”) wasn’t working for me. Would appreciate if someone told me how to solve that problem though. Hope this helps.

Edit: Also make sure to get rid of the old character by using character.Humanoid.Health = 0 or something.

You could use a HumanoidDescription to accomplish this.
HumanoidDescription | Documentation - Roblox Creator Hub
Humanoid # ApplyDescription | Documentation - Roblox Creator Hub

Ive tried something like this as a test

local description = game.ServerStorage.TeamCharacters.GoblinAvatar.Humanoid:GetAppliedDescription()

local rig = workspace.rigtoapp

rig.Humanoid:ApplyDescription(description)

but it just make the rig fully black, is there any easier way to do something like this
(i know i can manually make a humanoid description… BUT its very time consuming)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.