Hello,
I need an basic script that can work on any NPC.
I just want that NPC will come to me when I write “:come” command via chat.
And it will be commanded by only one or certain whitelisted players.
For example:
How can I do that?
Thanks
You would use a player.Chatted
event and also use :Humanoid:MoveTo()
function.
local Npc = script.Parent
local Humanoid = script.Parent.Humanoid
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.lower(Message) == ":come" then
Humanoid:MoveTo(Player.Character.HumanoidRootPart.CFrame.lookVector * 3)
end
end)
end)
Something to note is that this is just MoveTo()
it will just walk in a straight line towards the player, you will have to use path finding service to make the bot go around walls and jump.
Hello! This is an example from mine:
local human = script.Parent.Humanoid
local humanoidPos = player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * Vector3.new(5,0,5)
game.Players.PlayerAdded:Connect(function(player)
if player.Name == "cobainnn" then
player.Chatted:Connect(function(msg)
if msg == "BRUH" then
human:MoveTo(humanoidPos)
end
end)
end
end)
I hope this helps. In case you’ve tried this code, if anything went wrong, just let me know and I’ll rewrite it!
Worked nicely, thank you so much.
You are suppose to do that.
Same thing in my one too
the player value is not in the script thats why
I made a better version with path finding service:
https://i.gyazo.com/074f849941f894db0692b6a9777d8521.mp4
local PathfindingService = game:GetService("PathfindingService")
local Npc = script.Parent
local Humanoid = script.Parent.Humanoid
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.lower(Message) == ":come" then
local Path = PathfindingService:CreatePath()
Path:ComputeAsync(Npc.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position)
local WayPoints = Path:GetWaypoints()
for _, waypoint in pairs(WayPoints) do
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
end
end)
end)
Something else to note is:
That will only work if you say :come exactly.
But in my original script
This will work even if you say :COME :CoMe :cOmE you get the idea.
So the reason why it showed up, is because I accidentally defined the variable outside the events. So my guess is if you put it in Chatted event, it’ll work. I’ll try the code once more,
You put the script in the NPC, right?
Yes I did, if the npc, the npc I got doesnt have a humanoidrootpart so if yours does you would change this line:
To
Path:ComputeAsync(Npc.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position)
Mine works fine, or you can use the updated version.
Path:ComputeAsync(Npc.Torso.Position, Player.Character.HumanoidRootPart.Position)
Uh… I don’t think you can use Torso, only UpperTorso and LowerTorso?
- Torso is not a valid member of Model "Workspace.NPC"
Read what I said in the post
Change torso to HumanoidRootPart. The Npc I used doesnt have one
Is that go in local script or just script?
Just a script inside of the dummy
oh! it worked! (I just test it.)
deactivate
activate
Right now I need figure out how to make it follow me.