i have a script that is supposed to make player go to the npc’s character and go back if the player pressed “e” and is in npc’s character…or it’s supposed to do that…
script
local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Lol = game.Workspace.Lol
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E and Player.CameraSubject = Npc.Humanoid then --the error
camera.CameraSubject = Npc
Player.Character = Npc
else
Player.Character = Player.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 == Player.Character then
camera.CameraSubject = Npc
Player.Character = Npc
else
Player.Character = Player.Character.HumanoidRootPart
camera.CameraSubject = Player.HumanoidRootPart
end
end)
no, what am i doing in the script is that when i press e i go to the npc’s character, and when i press e again i go back to the character of me(aka player)
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer -- references the player
local Character = Player.Character or Player.CharacterAdded:Wait() -- references the players character
local Camera = game.Workspace.CurrentCamera -- references the camera
local NPC = game.Workspace.Npc
local LOL = game.Workspace.Lol
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E and Camera.CameraSubject == Npc:FindFirstChild("Humanoid") then
Camera.CameraSubject = Character:FindFirstChild("Humanoid")
elseif Key.KeyCode == Enum.KeyCode.E and Camera.CameraSubject == Character:FindFirstChild("Humanoid") then
Camera.CameraSubject = Npc:FindFirstChild("Humanoid")
end
end)
Put this script into StarterPack or StarterPlayerScripts.
I don’t exactly why you are trying to set Player.Character to Player.HumanoidRootPart because that won’t do anything, especially since you’re trying to set something to it’s own child.
local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Lol = game.Workspace.Lol
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E and camera.CameraSubject == Npc.Humanoid then
camera.CameraSubject = Player.Humanoid
elseif Key.KeyCode == Enum.KeyCode.E then
camera.CameraSubject = Npc.Humanoid
end
end)
I assume you are running this on the client.
Player.CameraSubject does not exist
Player.Character is read-only
You are setting Camera.CameraSubject to the NPC while checking if Camera.CameraSubject is the NPC
You are setting Camera.CameraSubject to the NPC, not the humanoid of the NPC
You are setting Camera.CameraSubject to a nil value (Player.Humanoid). Use Player.Character.Humanoid, instead of Player.Humanoid
You are setting Camera.CameraSubject to the NPC if the subject is already the NPC
local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Lol = game.Workspace.Lol
local deb = true
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E and not deb then
camera.CameraSubject = Player.Humanoid
elseif Key.KeyCode == Enum.KeyCode.E and deb then
camera.CameraSubject = Npc.Humanoid
end
end)
try this
make sure its a local script in the starter character scripts
local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Lol = game.Workspace.Lol
local deb = false
UIS.InputBegan:Connect(function(Key, Chatted)
if Chatted then
return
end
if Key.KeyCode == Enum.KeyCode.E and not deb then
camera.CameraSubject = Character.Humanoid
elseif Key.KeyCode == Enum.KeyCode.E and deb then
camera.CameraSubject = Npc.Humanoid
end
end)
Also set your cam type to scriptable like this camera.CameraType = Enum.CameraType.Scriptable
But do not do the camera subject I think it is still broken