#AI Pathfinding
123 messages · Page 1 of 1 (latest)
local pfs = game:GetService('PathfindingService')
local bot = workspace:WaitForChild('bot')
local jumpscareremote = game.ReplicatedStorage.jumpscare
local radius = bot.hitbox
bot.PrimaryPart:SetNetworkOwner(nil)
local path : Path = pfs:CreatePath({
AgentRadius = 5,
AgentHeight = 5,
AgentCanJump = false,
})
local debounce = false
radius.Touched:Connect(function()end)
game.Players.PlayerAdded:Connect(function(plr)
local connection
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild('HumanoidRootPart')
hrp.Touched:Connect(function(part)
if part.Parent:FindFirstChild('Humanoid') and part ~= radius then
if debounce then return end
debounce = true
char:FindFirstChild('Humanoid').Health = 0
jumpscareremote:FireClient(plr)
task.wait(5)
debounce = false
end
end)
if connection then
task.cancel(connection)
end
connection = task.spawn(function()
while task.wait() do
local partgoto
path:ComputeAsync(bot.HumanoidRootPart.Position,hrp.Position)
if path.Status == Enum.PathStatus.Success then
for i,v in ipairs(path:GetWaypoints()) do
bot.Humanoid:MoveTo(v.Position)
bot.Humanoid.MoveToFinished:Wait()
end
end
end
end)
end)
end)
there
@wispy socket
bro i need some explaining not just a script ;-;
its like a rocket-scientist trainee asking for help and you just give him a freaking rocket and tell him "you are welcome"
@smoky wave
There are TONS of tutorials on online
If you can’t understand a tutorial from AlvinBlox or DevKing, then you are too ahead of your skill
alvinblox doesnt have a tutorial on pathfinding
but i get what you mean
TheDevKing does
alr
slight problem ,its outdated
It’s not outdated wtf
THAT is literally how anyone would do pathfinding
You’re not meant to out anything inside :Wait
And pair should be pairs
Actually change that to ipairs
whats wrong on line 13 tho
thats how he did it in the video tho
That line is meant to wait until it moves to the destination
No he didn’t
I’ve seen it
;-;
Remove it
Remove it
I have no idea why he put a argument in there
Then remove the last line too
You should have up to line 13
so im removing MoveToFinished?
Remove the 2
What does it say
Workspace.Dummy.AI:13: Expected '(', '{' or <string> when parsing function call, got ':' - Studio - AI:13
It’s human.MoveToFinished:Wait()
No
Listen
You put human:MoveToFinsihed:Wait()
See the difference?
yeah i do
Yeah so change it
lemme run it
another error
Workspace.Dummy.AI:12: attempt to index nil with 'Position' - Server - AI:12
Make sure you read it carefully
it still doesnt work tho
Wdym?
Do me favour,
i hate coding ai i feel you
Add a line and print “path.Status”
Where did you print it
i just wrote print(path.Status)
I said where
line 17
Show me your entire script
Put it before the for loop
Wait hold on
same result
Remove it anyway you don’t need it
maybe theres something wrong with my dummy
ba du bah
Is your model unanchored?
ye
Change pairs to ipairs
ask the squidward killer games dev
It’s not gonna fix it but do it anyway
LOL
lmao
me when accidental fix
So it works?
may i ask whats the difference between pairs and ipairs
yeah
i was told to use pairs on both arrays and dictionaries
ipairs os guaranteed to iterate in order
i have no idea 💯
💯💯💯
Use pairs for when iterating in dictionaries
can you rephrase it
But in most cases you should use ipairs because it’s faster
alr
Say you have an array with 1, 2, 3, 4 and so on
ye
If you use pairs,
It can sometimes iterate in a random order
But using ipairs iterates in order so that it will go, 1, 2 3, 4
It’s also faster too
oh i didnt know that