Problem with character

Hello fellow developers, I’m having this problem with a script it’s where you learn new skills and jukes basically, for myself and it keeps saying “Workspace.Monster.Script:13: attempt to index nil with ‘Character’”, I don’t know what that means, obviously it can’t tell what a character is, but I don’t understand how I would make it understand it is.

What I want it to do: to chase the player

What it’s inside of: Character model

Here is the script,


local object = script.Parent
local human = object:WaitForChild("Humanoid")
local torso = object:WaitForChild("Torso")

local PathFindingService = game:GetService("PathfindingService")

local path = PathFindingService:CreatePath()

local player = players.LocalPlayer

local HRP = player.Character.HumanoidRootPart

local runservice = game:GetService("RunService")

runservice.Heartbeat:Connect(function()
	path:ComputeAsync(torso.Position, HRP.Position)
	local waypoints = path:GetWaypoints()

	for i, waypoint in pairs(waypoints) do

		if waypoint.Action == Enum.PathWaypointAction.Jump then
			human:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		human:MoveTo(waypoint.Position)
		human.MoveToFinished:Wait(2)
	end
end)

Thanks!

LocalPlayer is only available on the client, in local scripts. If this is a server script youre going to have to get the player through some other means.

This will only find the player in local scripts, you will need to get the player via game:GetService("Players")

I did, at the top of script I put it in there

Is there any way I could put it in to a server script and it work?

You will have to get all of the players in the game currently, and pick one of them. You cant use local player in a server script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.