How to turn my player character into an Npc character?

I wanted to make a proximity prompt where if you hold it down, your character will turn into another character (basically a kit system). I did not know how to do this so I did some research on Devforum and found this post which helped me a bit. However, it was a bit confusing and I ended up with an error:

Workspace.Shop.Noob Kit.Kit NPC.ProximityPrompt.Script:25: attempt to index nil with 'HumanoidRootPart'

Here is my script:


prompt.TriggerEnded:Connect(function(player)
	
	print(player)
	
	local gamePassId = 22080195 -- Gamepass ID here
	
	local userId = player.userId
	
	if game:GetService(("MarketplaceService")):UserOwnsGamePassAsync(userId,gamePassId) == false then
		
		print("Player Does Not Have Gamepass")
		
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId)
		
	else
		
		print("Player Has Gamepass")
		
		local character = player.Character
		
		local clone = character:Clone()
		
		clone.HumanoidRootPart.Position = character.HumanoidRootPart.Position
		
		local newchar = game:GetService("ServerStorage").KitClones.NoobKit

		character = newchar

		character.HumanoidRootPart.Position = newchar.HumanoidRootPart.Position

	end

end)

Any help on how to fix this error and/or achieve what I want to achieve would be greatly appreciated. Thanks.

FYI This script is inside the ProximityPrompt

5 Likes

Also here are 2 images of the Explorer, in case it helps:

prompt.TriggerEnded:Connect(function(player)

	print(player)

	local gamePassId = 22080195 -- Gamepass ID here

	local userId = player.userId

	if game:GetService(("MarketplaceService")):UserOwnsGamePassAsync(userId,gamePassId) == false then

		print("Player Does Not Have Gamepass")

		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId)

	else

		print("Player Has Gamepass")

		local character = player.Character

		local clone = character:Clone()

		clone.HumanoidRootPart.Position = character.HumanoidRootPart.Position

		local newcharLocation = game:GetService("ServerStorage").KitClones.NoobKit
		local newchar = newcharLocation:Clone()
		newchar.Parent = workspace
		newchar.Name = player.Name
		
		player.Character = newchar
		
		player.Character.HumanoidRootPart.Position = clone.HumanoidRootPart.Position

	end

end)
1 Like

I still receive the same error:

1 Like

Is this line 25? If it is, then the NPC character must not have a HumanoidRootPart.

1 Like

It has a HumanoidRootPart:


Unless I’m doing something wrong :frowning_face:

Can you show me the whole script, or at least tell me what is line 25?

1 Like
local prompt = script.Parent

prompt.TriggerEnded:Connect(function(player)

	print(player)

	local gamePassId = 22080195 -- Gamepass ID here

	local userId = player.userId

	if game:GetService(("MarketplaceService")):UserOwnsGamePassAsync(userId,gamePassId) == false then

		print("Player Does Not Have Gamepass")

		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId)

	else

		print("Player Has Gamepass")

		local character = player.Character

		local clone = character:Clone()

		clone.HumanoidRootPart.Position = character.HumanoidRootPart.Position

		local newcharLocation = game:GetService("ServerStorage").KitClones.NoobKit
		
		local newchar = newcharLocation:Clone()
		
		newchar.Parent = workspace
		
		newchar.Name = player.Name

		player.Character = newchar

		player.Character.HumanoidRootPart.Position = clone.HumanoidRootPart.Position

	end

end)

I copied what you posted earlier

clone.HumanoidRootPart.Position = character.HumanoidRootPart.Position

is line 25

I think R15 discludes HumanoidRootPart. I’m not sure, but your character definitely doesn’t have a HumanoidRootPart.

If your game is set to R15, set it to R6. Game Settings > Avatar > Avatar Type
image

1 Like

I get the same error. I changed the Avatar type to R6 and got the exact same error. :confused:


I have a HumanoidRootPart

1 Like

Change line 25 to this:

clone.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position)
2 Likes

Just do: Character:WaitForChild("HumanoidRootPart")

2 Likes

Same error

:exploding_head: ahhhhhhhhhhhhhhh

1 Like

How about clone:WaitForChild('HumanoidRootPart'). If the output is infinite yield try to look yourself the hrp inside the explorer from server or client side, if its really there.

2 Likes

I got the same error again :confused: idk why it doesnt work

1 Like

where do i put this? im not sure

1 Like

Try run a check.

ProximityPrompt.PromptTriggered:Connect(function(Player)

print(Player.Character:FindFirstChild('HumanoidRootPart'))

end)
2 Likes

It prints out HumanoidRootPart

1 Like