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)
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)
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)
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”)
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?
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?
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)