Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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.

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? Shawnyg 4330 — 7y
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. Eagle_RG 2 — 7y
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. AstrealDev 728 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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 :)

Ad

Answer this question