Is it possible to make a player become R6 when they touch a certain part?

The script I gave should save any hats listed in the humanoid description

if you want to save hats that may be added in by your game you could try looping through the children of the player’s character

Here’s a script I came up with
(note that transforming between r6 and r15 comes with a lot of bugs an example is the camera resetting which I tried to fix but found my fix to be far too unreliable to implement)

-- Script located literally anywhere that a script can run

--[[ Config ]]--
local RigType : Enum.HumanoidRigType = Enum.HumanoidRigType.R15 -- Model to convert player's into
local ConvertPart : Instance = workspace.SpawnLocation -- Part to convert player into specified RigType
local ConvertBackPart : Instance = workspace.Baseplate -- Part to convert player back into their original RigType (set to nil to disable)
local TransformDelay : number = 0.5 -- Time to wait before transforming (at least 0.25 recommended)

--[[ Services ]]--
local Services = table.freeze {
	Workspace = game:GetService("Workspace");
	Players = game:GetService("Players")
}

--[[ Variables ]]--
local TransformedPlayers : {Player} = {}
local Debounce : boolean = false

--[[ Config Check ]]--
do
	if RigType ~= Enum.HumanoidRigType.R6 and RigType ~= Enum.HumanoidRigType.R15 then
		error("Script requires a valid RigType enum")
	end
	if typeof(ConvertPart) ~= "Instance" then
		error("ConvertPart is not a valid object")
	end
	if not ConvertPart:IsA("BasePart") and not ConvertPart:IsA("UnionOperation") then
		error("ConvertPart is not a valid part or union.")
	end
	if ConvertBackPart and typeof(ConvertBackPart) ~= "Instance" then
		error("ConvertPart is not a valid object")
	end
	if ConvertPart and not ConvertBackPart:IsA("BasePart") and not ConvertBackPart:IsA("UnionOperation") then
		error("ConvertPart is not a valid part or union")
	end
	if typeof(TransformDelay) ~= "number" then
		error("TransformDelay is not a valid number")
	end
end

--[[ ConvertPart Touched Handler ]]--
ConvertPart.Touched:Connect( function( TouchPart : BasePart )
	-- Checks
	if Debounce then
		return
	end
	
	local Player : Player = Services.Players:GetPlayerFromCharacter(TouchPart.Parent)
	
	if not Player then
		return
	end

	if table.find(TransformedPlayers, Player) then
		return
	end
	
	if Player.Character.Humanoid.RigType == RigType then
		return
	end
	
	Debounce = true
	
	task.wait(TransformDelay)
	
	-- Add Players to TransformedPlayers table
	table.insert(TransformedPlayers, Player)

	Debounce = false
	
	-- Variables
	local OriginalCFrame : CFrame = Player.Character.HumanoidRootPart.CFrame
	local OriginalCharacter : Model = Player.Character
	local NewCharacter : Model = Services.Players:CreateHumanoidModelFromDescription( OriginalCharacter.Humanoid.HumanoidDescription, RigType, Enum.AssetTypeVerification.Default )
	local Connections = {}

	-- Configure NewCharacter
	NewCharacter.HumanoidRootPart.CFrame = OriginalCFrame
	NewCharacter.Name = Player.Name
	NewCharacter.Humanoid.DisplayName = Player.DisplayName
	
	-- Loop through original character to see if any missing accessories or scripts are found
	for _, child: Instance in pairs(OriginalCharacter:GetChildren()) do
		if (not child:IsA("Hat") and not child:IsA("Accessory") and not child:IsA("Script") and not child:IsA("LocalScript")) or child.Name == "Animate" then
			continue
		end
		
		if not NewCharacter:FindFirstChild(child.Name) then
			child:Clone().Parent = NewCharacter
		end
	end
	
	-- Set Player's character to NewCharacter
	OriginalCharacter.Parent = nil
	Player.Character = NewCharacter
	NewCharacter.Parent = workspace
	
	-- Destroy OriginalCharacter if player dies to prevent possible lag
	table.insert(Connections, NewCharacter.Humanoid.Died:Connect(function()
		-- Disconnect Connections
		for _, connection: RBXScriptConnection in Connections do
			connection:Disconnect()
		end
		
		-- Remove Player from TransformedPlayers table
		table.remove(TransformedPlayers, table.find(TransformedPlayers, Player))
		
		OriginalCharacter:Destroy()
	end))
	
	-- Destroy OriginalCharacter if player leaves to prevent possible lag
	table.insert(Connections, Player.Destroying:Connect(function()
		-- Disconnect Connections
		for _, connection: RBXScriptConnection in Connections do
			connection:Disconnect()
		end
		
		-- Remove Player from TransformedPlayers table
		table.remove(TransformedPlayers, table.find(TransformedPlayers, Player))
		
		OriginalCharacter:Destroy()
	end))
	
	-- Convert back if player touches ConvertBackPart
	if ConvertBackPart then
		table.insert(Connections, ConvertBackPart.Touched:Connect(function(TouchPart : BasePart)
			-- Make sure the player touching is the player we transformed
			if Player ~= Services.Players:GetPlayerFromCharacter(TouchPart.Parent) then
				return
			end
			
			-- Disconnect Connections
			for _, connection: RBXScriptConnection in Connections do
				connection:Disconnect()
			end
			
			-- Configure OriginalCharacter
			OriginalCharacter.HumanoidRootPart.CFrame = NewCharacter.HumanoidRootPart.CFrame
			OriginalCharacter.HumanoidRootPart.Anchored = false
			
			-- Loop through new character to see if any missing accessories or scripts are found
			for _, child: Instance in pairs(NewCharacter:GetChildren()) do
				if (not child:IsA("Hat") and not child:IsA("Accessory") and not child:IsA("Script") and not child:IsA("LocalScript")) or child.Name == "Animate" then
					continue
				end
				
				if not NewCharacter:FindFirstChild(child.Name) then
					child:Clone().Parent = OriginalCharacter
				end
			end
			
			-- Set Player's character to OriginalCharacter
			NewCharacter:Destroy()
			Player.Character = OriginalCharacter
			OriginalCharacter.Parent = workspace
			
			-- Remove Player from TransformedPlayers table
			table.remove(TransformedPlayers, table.find(TransformedPlayers, Player))
		end))
	end
end)

In the future try not to respond to old topics like this, instead you could message the person you have a question for

In case you need to understand more about humanoid descriptions:

2 Likes