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)

there is this error too

1 Like

you need to end the function. You have 3 if statements and a function but only 3 ends.

1 Like

uh where do i put the end? (thirtyyyy)

1 Like

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
1 Like

you reposted your topic?

roblox is cool

1 Like

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)

That probably means that the variable ‘Chatted’ is nil or not defined.

where do i switch this to?(thirty)

1 Like

ye since it was not solved and no one responeded

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)
1 Like

You are not allowed to repost topics.

1 Like

it changed it a bit and added the error so it wasn’t a total repeat

1 Like

huh…i pressed e and nothing happens…not in the output either

Is it a LocalScript? It has to be a LocalScript for InputBegan.

1 Like

Screen Shot 2021-05-25 at 4.21.58 PM
yea

Well then, I have no idea how to fix this.

1 Like

alr thx for the help ima do a bit of trying and googling