Script Not Working

I am making a script so that I spawn a character next to my player then it runs forward.

My local script (I forgot how to make it highlighted)

"local UserInputService = game:GetService(“UserInputService”)

local function E()
local keysPressed = UserInputService:GetKeysPressed()
for _, key in ipairs(keysPressed) do
if key.KeyCode == Enum.KeyCode.E then
game.ReplicatedStorage.Remotes.E:FireServer(game.Players.LocalPlayer)
print(“a”)
end
end
end

UserInputService.InputBegan:Connect(E)"

My ServerScript

local function NarutoRun(plr , player)
print(player)
local naruto = game.ReplicatedStorage.Naruto:Clone()
naruto.Parent = game.Workspace

wait(1)
naruto.Humanoid:MoveTo(plr.Character.Torso.position + Vector3.new(0, 0, 10))

end

game.ReplicatedStorage.Remotes.E.OnServerEvent:Connect(function(plr, n)
NarutoRun()
end)

Here is a better view of your script (no changes were made below)

local UserInputService = game:GetService(“UserInputService”)

local function E()
	local keysPressed = UserInputService:GetKeysPressed()
	for _, key in ipairs(keysPressed) do
		if key.KeyCode == Enum.KeyCode.E then
			game.ReplicatedStorage.Remotes.E:FireServer(game.Players.LocalPlayer)
			print(“a”)
		end
	end
end

UserInputService.InputBegan:Connect(E)

-- My ServerScript

local function NarutoRun(plr , player)
	print(player)
	local naruto = game.ReplicatedStorage.Naruto:Clone()
	naruto.Parent = game.Workspace

	wait(1)
	naruto.Humanoid:MoveTo(plr.Character.Torso.position + Vector3.new(0, 0, 10))
end

game.ReplicatedStorage.Remotes.E.OnServerEvent:Connect(function(plr, n)
	NarutoRun()
end)

Add a print("Passed") after every line of codes. Then calculate how many time it said. After that, look for the where it stopped, that is where error happended.

Are you trying to move Naruto character to the player who presses E on their keyboard?

It does not have to be naruto but that’s the idea

1 Like

for got to include an error ServerScriptService.E:7: attempt to index nil with ‘Character’

Okay. Here are your fixed scripts:

Local Script:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemotesFol = ReplicatedStorage:WaitForChild("Remotes")
local KeyEvent = RemotesFol.E

local function PressedE(input, typing)
	print("received function call")

	if typing then
		return
	end
		
	if input.KeyCode == Enum.KeyCode.E then
		KeyEvent:FireServer()
		print("You pressed 'E' on your keyboard")
	end
end

UserInputService.InputBegain:Connect(PressedE)

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WorkSpace = game:GetService("Workspace")

local Event = ReplicatedStorage:WaitForChild("Remotes").E
local Naruto = ReplicatedStorage:WaitForChild("Naruto")

local function NarutoRun(plr)
	print("Received Remote Event Notification")

	local CloneNaruto = Naruto:Clone()
	CloneNaruto.Parent = WorkSpace
	
	wait(1)
	CloneNaruto.Humanoid:MoveTo(plr.Character.HumanoidRootPart.Position + Vector3.new(0, 0, 10))
end

Event.OnServerEvent:Connect(function(player)
	NarutoRun(player)
end)
1 Like

Thanks so much but I have not worked with cframes and positions that much so how would i make it face the character?

1 Like

I am actually not sure how to do that. I apologize.
But you are very welcome, happy to help!

1 Like

Thank you very much for the Scripts :+1:

1 Like