Script not working

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)
2 Likes

Are there any errors? Try printing chatted.

Otherwise this might help: How to change custom character during game - #6 by goldenstein64

i have this error

Is that the whole script? Usually that error suggests that you haven’t added an ‘end’ to a function. Are there any red lines in your code?

You need one more end I think.