i have a script that is supposed to make player’s character when pressed a key and come back if the server detect that player’s character is in the npc and pressed the key again. my problem is that nothing is working
here’s my 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 then
if Player.Character == Character then
camera.CameraSubject = Npc
Player.Character = Npc
elseif Player.Character == Npc then
camera.CameraSubject = Character
Player.Character = Character
end
end
end)
Actually, I’m not sure. It looks fine to me. I just realised that you have ended the first if statement.
try changing this
if Player.Character == Character then
camera.CameraSubject = Npc
Player.Character = Npc
end
if Player.Character == Npc then
camera.CameraSubject = Character
Player.Character = Character
end
btw i got this error from my other animation script
Workspace.Npc.Animate:571: attempt to index nil with ‘Chatted’
this is the part btw
game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
local emote = ""
if (string.sub(msg, 1, 3) == "/e ") then
emote = string.sub(msg, 4)
elseif (string.sub(msg, 1, 7) == "/emote ") then
emote = string.sub(msg, 8)
end
if (pose == "Standing" and emoteNames[emote] ~= nil) then
playAnimation(emote, 0.1, 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 then
if Player.Character == Character then
camera.CameraSubject = Npc
Player.Character = Npc
end
if Player.Character == Npc then
camera.CameraSubject = Character
Player.Character = Character
end
end
end)