Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Where can I find info on how to call the player depending on what script Im in?

I still haven't found an answer to this. I can't find info on how to "call" or "get" or whatever it is. I want the NPC's to target players in my game, as they are the enemy. This code works for parts in the workspace but I can't figure out how to get him to target my player.

while true do
wait(2)
local character = game.Workspace.Player
local player = game.Players:GetPlayerFromCharacter(character)

	FindPath(player.UpperTorso.Position, 1, 1, 500) 
end

-- If I replace workspace.globe.Position with a part in workspace, it works fine.

This gives me the error: "Player is not a member of Workspace"

Im sorry to post again, but I totally didn't know how this website worked... If anyone has any help I am thankful. Im sorry again.

3 comments

0

Um, 100 lines? Just seeing the amount of lines makes people less likely to help you, without a certain number. What's the line of the error? Can you only paste the important parts such as variables, and the lines of the error?

0

Ok, Sorry... I can't get the player in the code at all. It always says player isn't there. I've tried every WaitForChild I can and I can't get it to work.

0

Eagle, you do realize that there's nothing in the workspace named 'Player' and that's why you get that error, right? game.Workspace.Player doesn't exist. That's not how you get the player.

1 answer

I'd like you to really quickly realize that typing game.Workspace.Player doesn't actually get the character. You have to get the player's character another way. Since this is a server-script you can't do LocalPlayer so you'll need to find an alternate way of finding the player. One way is using a RemoteEvent and then handling it in that script.

local character = game.Workspace.Player -- That doesn't work, there's nothing named 'Player' in the workspace.

Hope I helped, let me know :)

This discussion is preserved as it was. New answers, comments, and votes are closed.