hello! I have a script that makes my player go to the npc, idk how would I make it so that it detects if the player’s character is in the NPC, and if yes, then the player’s character go back to the player
My robot man 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
local Player = game.Players.LocalPlayer
if Key.KeyCode == Enum.KeyCode.E then
camera.CameraSubject = Npc.Humanoid
Player.Character = Npc
end
end)
Okay, it would help if you explained what this script is supposed to do. I’m assuming you want to be able to press E once, transfer control to the NPC, press E again, and transfer control back to your normal character?
I’m not sure, but I think you should change the Character from the server.
And you must clone the character so that it is not destroyed.
(remember to activate .Archivable before cloning it)
Camera has a CFrame value in it. You could try setting that value to the CFrame of the Npc’s humanoidrootpart and then you can add some studs so its not just right up against the npc.
UMM…now it just make my avater in the npc when i joined now…
if Key.KeyCode == Enum.KeyCode.E and Player.Character == Npc then
camera.CameraSubject = Player
Player.Character = Player
else
camera.CameraSubject = Npc
Player.Character = Npc
end
if Key.KeyCode == Enum.KeyCode.E and Player.Character == Player.HumanRootPart then
camera.CameraSubject = Npc
Player.Character = Npc
else
camera.CameraSubject = Player
Player.Character = Player
end