Error in my script

I have a script that is SUPPOSED to make me go to npc’s character when pressed e and come back if the server detect that I am inside NPC and pressed e
the script:

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer


UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E and Player.Character == Character then 
		camera.CameraSubject = Npc
		Player.Character = Npc
	else
		Player.Character = Player.Character.HumanoidRootPart
		camera.CameraSubject = Player.Humanoid
										
	end



end)

the error

what line is the error code sir

Player.Character Needs to be a model, and the HumanoidRootPart is a part. You won’t be able to set it to anything other than a model.


i changed the script to

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer


UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E and Player.Character == Character then 
		camera.CameraSubject = Npc
		Player.Character = Npc
	else
		Player.Character = Player.Character.HumanoidRootPart
		camera.CameraSubject = Player.Humanoid
										
	end



end)

so what do i change? do i do the whole character model?

I’m not sure what your trying to achieve, but if you want to change the player’s character you need to change it to a model, not a part like you are doing currently. You should do:
Player.Character = modelToChangeTo, instead of
Player.Character = HumanoidRootPart

Edit: I think I get what you’re trying to do, if you are trying to make the player’s character go back to it’s original avatar you should make store the player’s original character in a variable before changing it to the npc. This way you can do this:

    local UIS = game:GetService("UserInputService")
    local Character = script.Parent
    local Npc = game.Workspace.Npc
    local camera = workspace.CurrentCamera
    local Player = game.Players.LocalPlayer
    --getting original character before you change it
  local originalCharacter = plr.Character

    UIS.InputBegan:Connect(function(Key, Chatted)

    	if Chatted then
    		return
    	end
    	if Key.KeyCode == Enum.KeyCode.E and Player.Character == Character then 
    		camera.CameraSubject = Npc
    		Player.Character = Npc
    	else
    --changing the character back to it's original form
    		Player.Character = originalCharacter
    		camera.CameraSubject = Player.Humanoid
    										
    	end



    end)

is that all or do I have to name the player’s model


huh

oh haha sorry, I got the wrong variable,
replace line 7 with
local originalCharacter = Player.Character

You are currently trying to get the humanoid from the player, but you need to get it from the player’s character. So you would do:
camera.CameraSubject = Player.Character:WaitForChild(“Humanoid”)

oh nevermind(thirtyyyyyyyyyyyyyy)

What line is the error on? (31 charrrss)


and i can’t move lol

wait so is the goal of your script to teleport the player to an npc and allow them to walk around as that npc, and when they press e teleport them back to their character?

yeah it is. well the server detect if the player is in the npc and if not goes back

I’m not sure why your script is erroring, I’ve been playtesting your script and it works fine for me. Does anything happen to your character, like does it switch characters or can you control the other character?

i have a animation script but not local
lemme delete that and try

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
--getting original character before you change it
local originalCharacter = Player.Character

UIS.InputBegan:Connect(function(Key, Chatted)

	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E and Player.Character == Character then 
		camera.CameraSubject = Npc
		Player.Character = Npc
	else
		--changing the character back to it's original form
		Player.Character = originalCharacter
		camera.CameraSubject = Player.Character:WaitForChild("Humanoid")

	end



end)

like this right?

The character may not have loaded, change character to player.Character or player.CharacterAdded:Wait()