So I'm working on a game where you can choose your character, and the way it works is that when the player selects a character from the menu, it fires a remote event, and multiple scripts check the second parameter of the event, which is the name of the ability (by default, the first parameter is the player), and if the second parameter of the remote event is equal to the name of the ability in the script, the code will run (I have made an example of this below). My issue is that I want to reduce the number of lines of code while also supporting characters with custom mesh body parts and making it more secure to prevent exploiters.

game.ReplicatedStorage.AbilityLoader.OnServerEvent:Connect(function(Player, AbilityName)

	if AbilityName == "Noob39" then
		Player:ClearCharacterAppearance()	
	

		local Character = Player.Character
		local Ability = game.ServerStorage.Abilities["Noob39"]

		if Character:FindFirstChild('Animate') then
			Character.Animate:Destroy()
		end
	
		for _, v in pairs(Ability:GetChildren()) do
			if v.Name ~= "SwordGrip" and v.Name ~= "Sword" and v.Name ~= "Band" then
				local Clone = v:Clone()
				Clone.Parent = Character
			end
		end
		
		for _, v in pairs(Character.Humanoid.Animator:GetPlayingAnimationTracks()) do 
			print(v.Name)
		end
	
		local RightBand = Ability.Band:Clone()
		RightBand.Parent = Character
		local Weld = Instance.new("Motor6D", Character.RightLowerArm)
		Weld.Part1 = RightBand
		Weld.Part0 = Character.RightLowerArm
		Weld.C1 = CFrame.Angles(0,math.rad(90),0):Inverse()
	
		local LeftBand = Ability.Band:Clone()
		LeftBand.Parent = Character
		local Weld = Instance.new("Motor6D", Character.LeftLowerArm)
		Weld.Part1 = LeftBand
		Weld.Part0 = Character.LeftLowerArm
		Weld.C1 = CFrame.Angles(0,math.rad(90),0):Inverse()
	
		local Sword = Ability.Sword:Clone()
		Sword.Parent = Character
		local SwordGrip = Ability.SwordGrip:Clone()
		SwordGrip.Parent = Character
		SwordGrip.Part1 = Sword
		SwordGrip.Part0 = Character.RightHand
	
		if Character.Head:FindFirstChildOfClass("Decal") then
			Character.Head:FindFirstChildOfClass("Decal"):Destroy()
			local NewFace = Instance.new("Decal", Character.Head)
			NewFace.Texture = "http://www.roblox.com/asset/?id=8260834354"
		end
	end
end)

2 comments

0

ya mean https://education.roblox.com/en-us/resources/education/arcade/customCharacter, if you put a model called "StarterCharacter" into StarterPlayer your character will spawn as it

0

There are multiple characters so using starter character wouldn't work