Hey everyone, I’m making a Nextbot game, how can I make a Safezone that NPCs can’t pass?
Construct some form of physical barrier and add all the players characters to X collision group, and all the Nextbots to Y collision group, then enable collisions for Y but disable them for X.
This post should also be moved to a more suitable category.
If your nextbot uses PathfindingService, you can add a PathfindingModifier to a part with CanCollide off and set PassThrough to false.
I found an alright solution to this problem when I was making a nextbot game.
First things first I personally put the Safezone inside a folder in the workspace called Safezones, after doing that make a local script and put it in starter gui, after that put a BoolValue in it and name it anything you want.
Now inside that script do this
local Safezone = game.Workspace.Safezones:WaitForChild(“Safezone”)
local bool = script.BoolValue
Safezone.Touched:Connect(function(hit)
if hit then
if hit.Parent:WaitForChild (“Humanoid”) or hit.Parent.Parent:WaitForChild (“Humanoid”) then
Bool.Value = true
end
end
end)
Safezone.TouchEnded:Connect(function(hit)
if hit then
if hit.Parent:WaitForChild (“Humanoid”) or hit.Parent.Parent:WaitForChild (“Humanoid”) then
Bool.Value = false
end
end
end)
After that put inside the ais script at the start
local bool = game.Players.LocalPlayer:WaitForChild(“PlayerGui”).LocalScript.BoolValue
Then in the part when the ai finds the player, right before the line of code where the ai starts going towards the player put
if bool.Value == false then
Put the line of code where the ai goes to the player
elseif bool.Value == true then
Player = nil – this means that the chosen player has been set to nil because they are in a Safezone and cannot be touched – note to make this line work the local value player has to be set to nil at the start and once the ai found the player it wants set it to that player it chose
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.