Good day! So, I made a script that what happens is, when the "Player" in Workspace, in studio, touches a brick, the NPC OPG goes to him and chases him until he touches the red brick. So, now that I know this works with just the Player model when testing, I am trying to get it in multiplayer online. I am having trouble getting the certain players name that touches the brick, then the NPC goes to that certain player. I know to you GetChildren in Players, but I have no idea what to do after that, any help?
LW = game.Workspace.zone.LW Mid = game.Workspace.zone.Mid OPG = game.Workspace.zone.OPG RW = game.Workspace.zone.RW z1 = game.Workspace.zone.Zones.z1 z2 = game.Workspace.zone.Zones.z2 z3 = game.Workspace.zone.Zones.z3 z4 = game.Workspace.zone.Zones.z4 opg1 = false lw1 = false mid1 = false rw1 = false z5 = game.Workspace.zone.Zones.z5 v = game.Players:GetPlayers() f = game.Players:GetFullName() LeftArm = game.Workspace.zone.OPG["Left Arm"] LeftLeg = game.Workspace.zone.OPG["Left Leg"] RightArm = game.Workspace.zone.OPG["Right Arm"] RightLeg = game.Workspace.zone.OPG["Right Leg"] Head = game.Workspace.zone.OPG.Head HumanoidRootPart = game.Workspace.zone.OPG.HumanoidRootPart Torso = game.Workspace.zone.OPG.Torso game.Players.PlayerAdded:connect(function() local plr = game.Players:GetPlayers() local f= game.Players:GetChildren() for i = 1, #f do print(f[i]) end end) z1.Touched:connect(function(hit,plrtouched) local hum = hit.Parent:FindFirstChild("Humanoid") local opg = hit.Parent:FindFirstChild("OPG") if opg1 == false and hit.Parent:FindFirstChild("Basketball") then opg1 = true print("Found Player") local plr = game.Players:GetPlayers() local f= game.Players:GetChildren() while opg1 == true do wait(0.9) OPG.Humanoid.WalkToPoint = game.Workspace.plrtouched.Basketball.Position - Vector3.new(5,0,3) end else print("Did not find player") end end) z5.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if opg1 == true and hum then opg1 = false z1.Parent = game.Lighting OPG.Humanoid.WalkToPoint = Vector3.new(-1.344, 13.419, -26.512) wait(5) z1.Parent = game.Workspace.zone.Zones else return false end end)
So if I understand your question, you are trying to find the player based on their character. If this is what you are trying to do, there is a method for this:
As an example, let's say a player touched a block with their leg.
script.Parent.Touched:connect(function(hit) -- Assuming script is inside part -- Hit corresponds to what touched it, in this situation, it is the leg local character = script.Parent -- This is the character model, the parent of the leg local player = game.Players:GetPlayerFromCharacter(character) -- This gets the corresponding player from the character model end)
I hope that made sense, if I need to elaborate in a different manner, let me know.