#Pathfinding not catching player

1 messages · Page 1 of 1 (latest)

sick owl
#

I have an enemy using roblox pathfinding, the enemy gets to the player super easy. But the problem is that as long as the player is running, the enemy keeps going to where the player was 1 frame earlier and just will never reach the player.
Increasing the speed can work, but only if its so incredible high that its like 4x the players speed and that messes with the point of the game.
Is there a way around this such as ways for it to calculate where the player is going to be, or other methods to help the enemy reach the player whilst the player is running

broken crow
#

server latency

#

try doing it on the client

sick owl
broken crow
hexed mantleBOT
#

studio** You are now Level 2! **studio

broken crow
#

client move npc

sick owl
sick owl
# broken crow client move npc

so should i be using an event using :FireAllClients for this? And if so then how accurate will it show the enemy for the clients?

broken crow
sick owl
broken crow
sick owl
broken crow
#

it basically gives the client permission to replicate it to other clients

sick owl
broken crow
#

HumanoidRootPart:SetNetworkOwner(player)

#

do it on the server

#

and dont forget to check HumanoidRootPart:CanSetNetworkOwnership()

sick owl
#

okay so i set the network owner of the root part every time it finds a player on my RunService.Heartbeat

#

if it finds a player then it will do its calculations and then send an event with :FireAllClients that will move the npc?

sick owl
broken crow
broken crow
sick owl
#

wait

#

i think i understand

broken crow
#

yes

#

i said that

sick owl
#

you check first then do

broken crow
#

yea

#

cuz

#

it will fail if you cant setnetworkownership

#

like if the rootpart is anchored

#

so you check with that

sick owl
#

ahh i see okay, so let me just move everything over to the client, and then if i find any problems ill come back

#

thank you so much so far btw

#

Okay got a question, so you said that the network ownership replicates the script from the network owners script. How do i make it do that, or does it do that automatically?

broken crow
sick owl
broken crow
hexed mantleBOT
#

studio** You are now Level 3! **studio

broken crow
#

so you dont need to use fireallclients for this

#

just use fireclient

sick owl
#

and after firing client, it will just update all other clients

broken crow
#

yep

sick owl
#

thats actually really helpful and cool, i never knew this

#

this will definitely help me in future too hah

broken crow
#

so basically
server > your client > server > other clients

sick owl
#

got it

broken crow
#

keep in mind exploiters (cheaters) can manipulate the server and move the rig somewhere else, but we dont talk about that

sick owl
broken crow
#

yea i find it hard to deal with them without messing up your game with a bunch of checks

sick owl
#

it makes my coding so messy all the time, i mean seriously, why would i want to mess up my beautiful structuring

#

look at it

#

So neatly layed out

broken crow
#

networkownership is the reason why exploiters go to natural disaster survival

broken crow
#

theyre doing everything they can with the debris 😭

#

making it orbit into them and things

sick owl
#

haha iv seen that actually

#

okay so a small issue has occured here

broken crow
#

what is it?

sick owl
#

When im firing the client, i need the player on the other side, would i do it like usual with network owner, so Players.LocalPlayer or would i find the network owner and that be the player

#

or do i send it twice the the event

#

like this

broken crow
#

no no

#

just do game.Players.LocalPlayer

sick owl
#

thats what i thought, but i thought that might interrupt the other players when it replicates the script

broken crow
sick owl
#

because right here im setting the nearestPlayer to Player.LocalPlayer and if the script is replicated, surely that would make the enemy move to the each player instead of the network owner

broken crow
sick owl
broken crow
#

because

#

you basically send a message to the client "hey you're the one being chased, move the enemy to your character!"

#

and because that client has a networkownership on the humanoidrootpart, it will automatically appear on other players

sick owl
#

okay thats good, im getting alot of errors, so im gonna try to get these out the way and then ill see if i run into another issue

#

okay, so when firing the event it needs the player, i currently have the character but when i use :GetPlayerFromCharacter() it doesnt seem to work, it just says its not a valid member of model

broken crow
#

ignore packet, its basically just a remoteevent

sick owl
#

okay so now im confused

#

not by what you sent

#

but im using a function rn to get the nearest player

broken crow
#

yes

sick owl
#

the function returns the player.Character which is fine

broken crow
#

yep

sick owl
#

then when it gets down to firing the event i want to get the player so i use nearestPlayer:GetPlayerFromCharacter()

broken crow
#

wait wait no

#

go back

sick owl
#

okay, to what?

broken crow
sick owl
#

i tried that, but then i get weirder messages in errors

broken crow
#

what is the error

sick owl
#

wait lemme do it

broken crow
#

yeah

sick owl
#

ignore "player argument must be a Player object"

broken crow
#

wait

sick owl
#

thats because i have "player" in there

broken crow
#

whats line 35

sick owl
#

like 35 is second there

#

if blah == nil

broken crow
#

nearestPlayer doesnt exist

sick owl
#

ah

broken crow
#

if not nearestPlayer then return end

sick owl
#

added it under

broken crow
#

yea

#

try it now

sick owl
#

no errors

#

we good

#

nvmmmmmmm

broken crow
#

what is it now

sick owl
#

its just an infinite yield for humanoidrootpart

#

lemme find it rq i can fix that

broken crow
#

alr

sick owl
#

no errors now

#

okay lemme test with the enemy

#

wellll it works better

#

but even with a really fast enemy, the enemy is closer but still like 1 stud behind the player

#

just out of range

#

i guess best fix is to make the enemy hitbox slightly bigger

coral plank
#

yes

hexed mantleBOT
#

studio** You are now Level 20! **studio

broken crow
#

dude what

hexed mantleBOT
#

studio** You are now Level 4! **studio

broken crow
#

he got summoned or smth

sick owl
#

lmaooo

#

yea

#

btw, you dont wanna know what you just helped me make

broken crow
#

what is it

sick owl
#

Escape Scotland

broken crow
#

huh

sick owl
#

heres the enemy

broken crow
#

dude what 😭

#

the hitbox's big enough, no need to expand it

#

😭

sick owl
#

its actually so cursed im not joking

sick owl
sick owl
#

its really good

#

the audio is the best part

#

you can test out the creation you helped me make

broken crow
#

its gonna be like a fever dream

#

lmao

sick owl
#

whats your rblx user

broken crow
#

miko100karakter

sick owl
#

can you send game links here?

#

you can

#

this is great

broken crow
#

yeaa

halcyon arrow
#

oh my god no wayyyy

sick owl
#

send your user ill add you as playtester rq

sick owl
broken crow
#

hol on

sick owl
#

i need honest review tho, if i finished this game do you think it would be front page?

broken crow
#

add brainrots

#

if you want frontpage

sick owl
#

nah, scotland

#

did you join up?

broken crow
#

wait wait

sick owl
#

sorry im excited

#

first playtester of Escape Scotland

broken crow
#

fair enough

#

so uh

sick owl
#

whatsup

broken crow
#

i havent verified

#

but

sick owl
#

but

broken crow
#

😭 😭

#

um

#

im not respawning

sick owl
#

😭

#

idk why

broken crow
#

dam

#

best game ever

#

this deserves an oscar

sick owl
#

why you not respawning

#

also, why does he stand still for like 5 seconds after killing someone?

broken crow
#

idk i tried respawning like 3 times

#

didnt work

#

what audio is BLESSING my ears rn

sick owl
#

wait im gonna kill you

broken crow
#

ok yeah safe to say this game is realistic

#

you cant respawn

#

js do

#

game.Players.miko100karakter:LoadCharacterAsync()

sick owl
#

okay

broken crow
#

phew

sick owl
#

he takes too long to change targets

#

also, i need to add a check to see if the player is reachable, how do i do that?

broken crow
#

like

#

reachable as in what?

sick owl
#

like if there is pathing to them

broken crow
#

oh

sick owl
#

if theres no pathing to nearestPlayer them ignore them

broken crow
#

i remember something about pathfinding yeah

#

idk though

#

hold on

#

so basically

#

if the path doesnt exist, ignore nearestPlayer?

sick owl
#

how do i check if it exists

#

everything is deprecated

broken crow
#

theres a code sample

#

``local Workspace = game:GetService("Workspace")
local PathfindingService = game:GetService("PathfindingService")

-- This model contains a start, end and three paths between the player can walk on: Snow, Metal and LeafyGrass
local PathOptionsModel = script.Parent.PathOptions
local startPosition = PathOptionsModel.Start.Position
local finishPosition = PathOptionsModel.End.Position

-- Create a path that avoids Snow and Metal materials
-- This will ensure the path created avoids the Snow and Metal paths and guides
-- the user towards the LeafyGrass path
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = false,
Costs = {
Snow = math.huge,
Metal = math.huge,
},
})

-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(startPosition, finishPosition)
end)

-- Confirm the computation was successful
if success and path.Status == Enum.PathStatus.Success then
-- For each waypoint, create a part to visualize the path
for _, waypoint in path:GetWaypoints() do
local part = Instance.new("Part")
part.Position = waypoint.Position
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Color = Color3.new(1, 0, 1)
part.Anchored = true
part.CanCollide = false
part.Parent = Workspace
end
else
print(Path unable to be computed, error: {errorMessage})
end``

sick owl
#

is it this?

#

-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(startPosition, finishPosition)
end)

broken crow
#

yeah that computes it

#

and then check the path.Status

sick owl
#

that checks

#

im confused

broken crow
#

you make a path

#

and then check if it exists

#

i guess

sick owl
#

should i just put an else here

broken crow
#

yeah

#

wait is that on the client

sick owl
#

yes

broken crow
#

i think there should also be one on the server

sick owl
#

how do i do that?

broken crow
#

do the same thing

#

but on the server

sick owl
#

okay this is too complicated now, im just gonna send both scripts to make this easier

broken crow
#

alr

sick owl
#
-- CLIENT
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")

--// Variables
local enemy = workspace:WaitForChild("Section1").Enemy
local humanoid = enemy:WaitForChild("Humanoid")
local rootPart = enemy:WaitForChild("HumanoidRootPart")

--// Move Enemy
local function MoveTo(targetPos)
    local path = PathfindingService:CreatePath({
        AgentRadius = 8,
    })
    path:ComputeAsync(rootPart.Position, targetPos)

    if path.Status == Enum.PathStatus.Success then
        for _, waypoint in pairs(path:GetWaypoints()) do
            humanoid:MoveTo(waypoint.Position)
            humanoid.MoveToFinished:Wait()
        end
    else
        
    end
end

--// Calculate Move
local function CalculateMove()
    local nearestPlayer = Players.LocalPlayer.Character
    local targetRootPart = nearestPlayer:WaitForChild("HumanoidRootPart")
    local targetHumanoid = nearestPlayer:WaitForChild("Humanoid")
    if targetHumanoid == nil then return end

    local distance = (targetRootPart.Position - rootPart.Position).Magnitude

    MoveTo(targetRootPart.Position)
end

--// Connections
ReplicatedStorage.RemoteEvents.MoveEnemy.OnClientEvent:Connect(CalculateMove)
#
-- SERVER
--// Services
local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Variables
local enemy = workspace.Section1.Enemy
local humanoid = enemy:WaitForChild("Humanoid")
local rootPart = enemy:WaitForChild("HumanoidRootPart")

--// Find Player
local function DetectPlayer()
    local nearestPlayer = nil
    local shortestDistance = math.huge
    
    for _, player in pairs(Players:GetPlayers()) do
        if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
            local distance = (player.Character.HumanoidRootPart.Position - rootPart.Position).Magnitude
            if distance < shortestDistance then
                shortestDistance = distance
                nearestPlayer = player
            end
        end
    end
    
    return nearestPlayer
end

--// Main Loop
RunService.Heartbeat:Connect(function()
    if humanoid.Health <= 0 then return end
    
    local nearestPlayer = DetectPlayer()
    if nearestPlayer == nil then return end
    if nearestPlayer.Character == nil then return end
    if nearestPlayer.Character.Humanoid.Health <= 0 then return end
    
    rootPart:SetNetworkOwner(nearestPlayer)
    
    ReplicatedStorage.RemoteEvents.MoveEnemy:FireClient(nearestPlayer)
end)

--// Kill Player
rootPart.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid and humanoid.Health > 0 then
        humanoid.Health = 0
        rootPart.AttackSound:Play()
    end
end)

broken crow
#

alr ill send u the script again

hexed mantleBOT
#

studio** You are now Level 5! **studio

broken crow
#

hol up

sick owl
#

sorry for letting you take over, its 3am for me so now im less enticed to learn and more enticed to get it done so i can sleep 😭

broken crow
#

lmao its alr 10am for me

#

wait uh

#

make a remotefunction

#

ReplicatedStorage.RemoteFunctions.MoveEnemy

sick owl
#

okay

broken crow
#

ok, also you should change remoteevent to unreliableremoteevent for performance reasons

broken crow
#

its exactly the same, so you dont need to change anything codewise

sick owl
#

whats the difference

#

I changed it but iv never seen this in my life

broken crow
# sick owl im confused

unreliable is just basically a light version of remoteevent, it drops an event if it fails to fire instead of waiting

sick owl
#

okay got it

broken crow
#

bcuz youre using HeartBeat its gonna kill the performance using a normal remoteevent yk

sick owl
#

okay understood

halcyon arrow
#

stop skidding

#

with ai

#

use ur own mental capacity

#

if u have some

sick owl
halcyon arrow
#

dont lie son

sick owl
#

why would i lie

halcyon arrow
#

its too obvious

#

try better to hide it

sick owl
#

i literally dont use ai

#

infact i do, i used it on my last game to solve some math i didnt want to do, thats about it really

broken crow
#

lmao, i remember someone calling me using ai when helping someone in hiddendev too

sick owl
#

I can see why people say its ai, i write too neat

halcyon arrow
#

ye u do

sick owl
#

i have OCD so im hella organised with my code and love to simplify so much

halcyon arrow
#

ive seen so many ai skidded code snippets

#

that i can detect whenever someone is skidding with ai

#

legit every time they try hiding it when its CLEARLY so obvious

#

from the unusual comments to the variable names to the logic

#

SO obviously ai skidde

#

d

sick owl
#

Im mostly against AI because of environmental reasons, but i like it for insperation and generating ideas

#

@broken crow do you have any updates

halcyon arrow
#

ykw

broken crow
# sick owl <@1162376353639829536> do you have any updates
--// Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Variables
local enemy = workspace.Section1.Enemy
local humanoid = enemy:WaitForChild("Humanoid")
local rootPart = enemy:WaitForChild("HumanoidRootPart")

--// Find Player
local function DetectPlayer()
    local nearestPlayer = nil
    local shortestDistance = math.huge

    for _, player in pairs(Players:GetPlayers()) do
        if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
            local check = ReplicatedStorage.RemoteFunctions.MoveEnemy:InvokeClient(player, rootPart.Position)
            if check ~= true then continue end
            
            local distance = (player.Character.HumanoidRootPart.Position - rootPart.Position).Magnitude
            if distance < shortestDistance then
                shortestDistance = distance
                nearestPlayer = player
            end
        end
    end

    return nearestPlayer
end

--// Main Loop
RunService.Heartbeat:Connect(function()
    if humanoid.Health <= 0 then return end

    local nearestPlayer = DetectPlayer()
    if nearestPlayer == nil then return end
    if nearestPlayer.Character == nil then return end
    if nearestPlayer.Character.Humanoid.Health <= 0 then return end

    rootPart:SetNetworkOwner(nearestPlayer)

    ReplicatedStorage.RemoteEvents.MoveEnemy:FireClient(nearestPlayer)
end)

--// Kill Player
rootPart.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid and humanoid.Health > 0 then
        humanoid.Health = 0
        rootPart.AttackSound:Play()
    end
end)```
halcyon arrow
#

lets ask AI if this is ai skidded

#

lol

broken crow
#
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")

--// Variables
local enemy = workspace:WaitForChild("Section1").Enemy
local humanoid = enemy:WaitForChild("Humanoid")
local rootPart = enemy:WaitForChild("HumanoidRootPart")

--// Move Enemy
local function MoveTo(targetPos)
    local path = PathfindingService:CreatePath({
        AgentRadius = 8,
    })
    path:ComputeAsync(rootPart.Position, targetPos)

    if path.Status == Enum.PathStatus.Success then
        for _, waypoint in pairs(path:GetWaypoints()) do
            humanoid:MoveTo(waypoint.Position)
            humanoid.MoveToFinished:Wait()
        end
    else

    end
end

--// Calculate Move
local function CalculateMove()
    local nearestPlayer = Players.LocalPlayer.Character
    local targetRootPart = nearestPlayer:WaitForChild("HumanoidRootPart")
    local targetHumanoid = nearestPlayer:WaitForChild("Humanoid")
    if targetHumanoid == nil then return end

    local distance = (targetRootPart.Position - rootPart.Position).Magnitude

    MoveTo(targetRootPart.Position)
end

--// Check
local function Check(targetPos)
    local path = PathfindingService:CreatePath({
        AgentRadius = 8,
    })
    path:ComputeAsync(rootPart.Position, targetPos)

    return path.Status == Enum.PathStatus.Success and true or false
end

--// Connections
ReplicatedStorage.RemoteEvents.MoveEnemy.OnClientEvent:Connect(CalculateMove)
ReplicatedStorage.RemoteFunctions.MoveEnemy.OnClientInvoke = Check```
sick owl
#

what did you change, i dont like copy pasting

broken crow
#

do a check

#

hold on

halcyon arrow
sick owl
#

okie dokie

broken crow
#

this is on the client

#

--// Check
local function Check(targetPos)
local path = PathfindingService:CreatePath({
AgentRadius = 8,
})
path:ComputeAsync(rootPart.Position, targetPos)

return path.Status == Enum.PathStatus.Success and true or false

end

ReplicatedStorage.RemoteFunctions.MoveEnemy.OnClientInvoke = Check

sick owl
halcyon arrow
#

not slick at all

#

son

sick owl
#

Because its perfect and pretty its all of a sudden AI

#

its code

#

I like organisation, if all your gonna do is critisize people on there code you can fuck off else where

worldly granite
#

hi hemmy

broken crow
halcyon arrow
#

js read the chats

sick owl
worldly granite
#

no this isn't AI

#

I know AI code

#

there would be comments

#

that are way more detailed

halcyon arrow
#

?

worldly granite
#

and better

#

than this

#

inside the functions

halcyon arrow
#

dingle

#

ur stupid

#

deadass

primal silo
#

You can delete comments

worldly granite
sick owl
#

my code is simple, i love relying on fundamentals

errant herald
primal silo
#

You have very descriptive variable names

halcyon arrow
#

do u not see the variable names

sacred portal
#

why are we here anyway

errant herald
halcyon arrow
#

and the logics

sacred portal
#

using AI is crime now?

#

wtf

safe fiber
sacred portal
halcyon arrow
#

dang

halcyon arrow
#

i summoned a lotta ppl

#

even a s4

broken crow
#

holy how many people are there

worldly granite
safe fiber
#

i was told to open this thread to see what op was saying

worldly granite
errant herald
safe fiber
#

and i was disappointed

errant herald
halcyon arrow
#

better be

sacred portal
#

it's not fun here

safe fiber
#

real

sacred portal
#

😠

worldly granite
#

yeah this is chudded

#

N G L

errant herald
halcyon arrow
#

do u not see this?!?

primal silo
#

Ok but come on nobody types out humanoid and all the service names and shortest distance etc the variable names scream ai

worldly granite
#

I lied

#

ts IS AI

halcyon arrow
#

atleast admit it

#

that ur a skid

worldly granite
#

how r u not referencing the player

sick owl
worldly granite
#

in the global scope of the script

#

but referencing the enemyh

worldly granite
#

and y r we using pairs

#

🥺

#

luau doesn't need pairs

primal silo
#

Can we see your ide

halcyon arrow
#

pairs and ipaits

safe fiber
halcyon arrow
#

ipairs*

#

r useless

primal silo
#

If it’s luau lsp I understand the variable names ig

broken crow
errant herald
halcyon arrow
#

the logic

errant herald
#

i also use ai

halcyon arrow
#

holy

#

ai is genuinely ruining

broken crow
halcyon arrow
#

mental capacity

worldly granite
#

AI is extremely useful

sick owl
#

@broken crow was it only this you added on server?

local check = ReplicatedStorage.RemoteFunctions.MoveEnemy:InvokeClient(player, rootPart.Position)
if check ~= true then continue end

halcyon arrow
#

in a way that it helps u learn

worldly granite
sick owl
halcyon arrow
#

but not straight up

worldly granite
#

I make it do all the mundane tasks for me

halcyon arrow
#

copying and pasting

worldly granite
#

so I can focus on the important things

halcyon arrow
#

then saying that U coded it

sick owl
broken crow
#

alr

worldly granite
#

AI -> useful learning tool and useful for mundane shi

sacred portal
halcyon arrow
#

do yall not see

#

the millions of brainrot slop games

#

on roblox

errant herald
# worldly granite AI is extremely useful

this is highkey fact it just get's to a point where if you let it code your entire game then I'd say that's a horrible idea but when it come's down to using it for simple thing's like debugging and small thing's inside your code you don't feel like doing or don't know how to do then it's fine.

worldly granite
errant herald
primal silo
# halcyon arrow mental capacity

Yeah its good for learning but to me its like a thing that cuts us 70/30 with less getting a net positive in terms of critical thinking bc I use it to learn sometimes but I also hate using it it’s depressing

sick owl
#

why am i being accused of using AI? Do i really have to show you my AI chatlogs from 3 months ago when i was figuring out bezier curves for my TD game

sick owl
primal silo
#

Like the Roblox code window

broken crow
#

@sick owl check dev console

worldly granite
sick owl
#

its clear

halcyon arrow
#

ok vro

worldly granite
errant herald
#

i just said allat shit to look smart i don't know shit about coding fr

hexed mantleBOT
#

studio** You are now Level 3! **studio

errant herald
sick owl
halcyon arrow
#

genuinely stop

#

😭

primal silo
worldly granite
#

it's roblox

#

it aint allat

primal silo
#

Notepad is an ide ppl love to say that don’t they

errant herald
worldly granite
worldly granite
halcyon arrow
worldly granite
#

making slop -> makes me money

broken crow
#

why are we talking about ai now

sick owl
#

@broken crow I got something!

errant herald
#

hey ik everyone here make's like 100k robux easily so can one of you highkey slide me a slight million

errant herald
broken crow
sick owl
#

ah

#

idk then

#

lemme put some prints

halcyon arrow
#

ok

#

well

#

im out

broken crow
sick owl
halcyon arrow
#

make sure to make some games with actual effort

errant herald
halcyon arrow
#

u stupid skids

errant herald
primal silo
worldly granite
#

son

worldly granite
#

don't make me skid check u

rugged vortex
#

Why was I pulled here from scripting

errant herald
errant herald
sick owl
safe fiber
errant herald
#

okay imma go try that

primal silo
rugged vortex
#

Tru

broken crow
#

almost 500 msgs js from the ai allegations 😭

sick owl
#

@broken crow okay so, its returning false every now and again, but thats about it

rugged vortex
#

Pyro gonna burn him

primal silo
#

Lemme ask ChatGPT what’s wrong with the script

#

/chatgpt fix this script

sick owl
rugged vortex
errant herald
#

isn't it like

sick owl
primal silo
#

It might not be ai it might be based on tutorials

errant herald
#

game.Work = yes work please or imma cry = yes

#

guys would this work?
game:Destroy() = pleasework

primal silo
#

No

broken crow
#

@sick owl might be better off invoking the client to move the npc, and then you check from there?

sick owl
#

@broken crow so if i remove the if check ~= true then continue end, it works but the enemy tweaks out

primal silo
#

If not a debugger then debug by hand

#

Step thru the code in your mind and write out and change the variable values as you go?

broken crow
#

wait wait

#

nvm

#

it does return false right

sick owl
#

returns false, but like once every 10 tries

broken crow
#

@sick owl you should make a new thread about this, the previous issue is fixed

sick owl
#

well it still doesnt work, but i removed the "and true or false" on the end of return path.Status

#

was more consistent with its responses

#

game me constant false

broken crow
#

that one returns true if path.Status is success, and returns false if path.Status isnt success

sick owl
#

okay so important note

#

i added a print under local nearestPlayer = DetectPlayer()

broken crow
#

what did it say

sick owl
#

it gives me nil for a while, then a spam list of my user, then goes back to nil for ages, even though im outside and waiting for it

#

lots of nil

broken crow
#

you know what

sick owl
#

i think its to do with the invoke

broken crow
#

just check if the player is inside that safezone instead of checking with pathfindingservice, i think its too inconsistent

sick owl
#

How do i check that?

broken crow
#

make a big box with cancollide checked off, massless checked on, and anchored checked on covering your safezone

sick owl
#

can i use player.IsTouching?

broken crow
#

wdym?

sick owl
#

like to check

#

wait

broken crow
#

no no

#

you can use basepart.Touched and basepart.TouchedEnded

sick owl
#

im confused

broken crow
#

with what

sick owl
#

could i do part:GetTouchingParts() and then check if anything touching.Parent has a humanoid

broken crow
#

yeah but you need to do that every frame

sick owl
#

true

#

whats a less intense way

broken crow
#

that

#

safezone.Touched and safezone.TouchedEnded event

sick owl
#

where do i use these

#

if safezone.Touched == true?

broken crow
#

wherevver you like

hexed mantleBOT
#

studio** You are now Level 6! **studio

broken crow
#

hol on

#

safezone.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        game.Players:GetPlayerFromCharacter(hit.Parent):AddTag("Safezone")
    end
end)

safezone.TouchEnded:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        game.Players:GetPlayerFromCharacter(hit.Parent):RemoveTag("Safezone")
    end
end)```
sick owl
#

ahh i se

broken crow
#

keep in mind that these are inconsistent as theyre relying on physics, but i think its worth the performance you get

#

then just put if player:HasTag("Safezone") then continue end on your detectplayer function

sick owl
#

okay

#

and im adding the tag on server right?

broken crow
#

yes

sick owl
#

okay i did that already

#

i dont think i need the check anymore

#

or the remote function

broken crow
#

yea

#

just

#

delete them

#

we dont use pathfinding anymore

sick owl
#

where tf is this]

#

i swear i deleted everything you added

broken crow
#

you still invokeclient

#

on the server

#

wait no

#

thats a remoteenvet

#

you deleted the remoteevent connection on the client 😭

sick owl
#

no i didnt

#

this might be because you made me change my remoteEvent for an unreliable one

broken crow
#

no, thats not a specific error for unreliableremoteevent

sick owl
#

i changed it and it worked

#

now the enemy works too

broken crow
#

that might happen because the event fired before client gets to connect it

sick owl
#

no it works now

#

the unreliable event didnt work

broken crow
#

yeah do whatever works

sick owl
#

why does the unreliable one not work//

#

maybe thats also why the check you added didnt work

#

maybe it did, but the unreliable event sucks

broken crow
#

idk man it should work

sick owl
#

join my game so we can see if it works with proximity

broken crow
#

k

sick owl
#

ill bait it to the front door and stand close, you go out the other door and keep a far distance

#

if he goes for you, then it works

#

well

broken crow
#

um

#

did you add the check

sick owl
#

yes

hexed mantleBOT
#

studio** You are now Level 16! **studio

sick owl
#

well

#

he still doesnt work

broken crow
#

wait

#

no no

#

its just that

sick owl
#

he doesnt work now

broken crow
#

hes not moving anymore

#

i think you added return

#

instead of continue

sick owl
#

i did 😭

broken crow
#

bru

sick owl
#

my bad

#

i didnt think it would fail

broken crow
#

return means it will ignore every other player too 😭

sick owl
#

do i just do "then end" ?

broken crow
#

no

#

do continue

sick owl
#

so if they have safezone tag then continue?????

broken crow
#

yes

sick owl
#

why???

broken crow
#

continue means go to the other player

#

check the other playeer

sick owl
#

ohhhh

broken crow
#

yes

sick owl
#

this look fine?

broken crow
#

yep

#

try publishing it

sick owl
#

published

broken crow
#

yeaaa

sick owl
#

perfect

#

can we check the 5 second wait it does after kill

#

lemme die

#

just stand outside

broken crow
#

sorry

#

forgot

sick owl
#

oaky

broken crow
#

huh

sick owl
#

so i know the problem

broken crow
#

what is it

sick owl
#

the player still exists when they are dead

broken crow
#

oh yeah

sick owl
#

just need another check to see if their health is 0

sacred portal
#

alright guys it's been 600 messages here, how many do yall plan

#

push it to 1k

sick owl
broken crow
#

yeah

broken crow
sick owl
#

literally already done

#

stealing my light 😭

#

republished

broken crow
#

yeayea

#

works

sick owl
#

go outside when i go out

broken crow
#

now

sick owl
#

where are you

broken crow
#

i think you need to fix the respawn problem 😭 😭

sick owl
#

not my fault

broken crow
#

maybe

sick owl
#

didnt change any respawn settings 😭

broken crow
#

put the rootpart.Touched event on the client

#

also they set the default of BreakJointsOnDeath to false

#

thats crazy

sick owl
#

okay 1 sec

#

its already on false

broken crow
#

yeah

#

roblox made it false

#

it was true before

sick owl
#

should it be true

broken crow
#

doesnt matter

#

its the reason deaths look realistic now

#

like

#

your joints dont break

sick owl
#

okay ill try it on break

#

i republished

#

beautiful

broken crow
#

should be good

#

this is going to front page

sick owl
#

factsss

#

its gonna be a puzzle game

#

so you have to solve puzzes to escape from scotland

broken crow
#

😭

sick owl
#

bro

broken crow
#

o

#

wait

sick owl
#

come outside?

broken crow
#

get closer

#

to me

#

WHAT

sick owl
#

well

broken crow
#

OHH

#

the networkownership is still mine

sick owl
#

OH

broken crow
#

it doesnt update because yk

sick owl
#

how do i fix that

broken crow
#

we ignored

#

maybe update the networkownership for every possible player being chased? idrk

#

since i have 300 ping, its gonna look choppy on you

sick owl
#

it does

broken crow
#

and vice versa

sick owl
#

wait

#

so how do i change the network ownershi

#

rn its doing it for every frame so idk

broken crow
#

if rootPart:CanSetNetworkOwnership() then rootPart:SetNetworkOwner(nearestPlayer) end

sacred portal
#

yall have been an hour here?

#

or no

broken crow
sick owl
#

yea

sacred portal
#

wow

#

keep going guys

broken crow
#

thats just to prevent error

sick owl
#

there was nothing in console

broken crow
#

huh

#

i guess just ignore it?

sick owl
#

how do i check the network owner

#

like print(rootPart.NetworkOwner)

broken crow
#

rootPart:GetNetworkOwner()

sick owl
#

okay, i republish with that print

#

lets see where it goes wrong

#

join up

molten carbon
#

damn

#

700 messages

#

big yap

sick owl
#

yea

#

your stil network owner

broken crow
#

i see

sick owl
#

its still doing it based off "Closest"

#

so i think continue is the problem

broken crow
#

but he doesnt continue to chase me when im in the safezone

sick owl
#

thats because of the tag

broken crow
#

OH

#

no

#

you need to

#

set networkownership to nil

#

so that the server owns it

#

before continue

sick owl
#

okay

broken crow
#

do it on health too

sick owl
#

like this?

broken crow
#

if player.Character.Humanoid.Health <= 0 then rootPart:SetNetworkOwner(nil) continue end

broken crow
sick owl
broken crow
#

yea

sick owl
#

republished

broken crow
#

try now

sick owl
#

wait

#

server didnt reset

#

still old server

#

okay i rejoined

#

its good

broken crow
#

try

sick owl
#

its not nil

broken crow
#

but itdoesnt move?

sick owl
#

your the network owner

#

like i said

broken crow
#

oh...

sick owl
#

i think its "continue"

broken crow
#

continue js means it will move onto the next player in Players:GetPlayers()

sick owl
#

lemme try fundamental stuff

broken crow
#

instead of js straight up giving up

sick owl
#

join back

#

nvm

broken crow
#

yeah see

sick owl
#

huh

#

back to how it was

broken crow
#

you know what

#

make a function Check(player)

#

and then return

#

like

sick owl
#

server or client

broken crow
#

server

sick owl
broken crow
#

yea

#

and then

#

put stuff that make it so npc can chase you

#

like

#

player.Character.Humanoid.Heatlh > 0

#

and player:HasTag("Safezone")

sick owl
#

i moved it from the other function

broken crow
#

no thats not gonna work

#

i meant put it on return

#

hold on ill show u

sick owl
broken crow
sick owl
#

what else do i add

broken crow
#

and then on the detect player
local canChase = Check(player)

#

you get it

hexed mantleBOT
#

studio** You are now Level 7! **studio

sick owl
#

if not canChase then continue end?

broken crow
#

no

#

put distance inside if canChase then

#

and then put

#

else

#

rootPart:SetNetworkOwner(nil)

#

end

sick owl
#

huh

#

if i put distance in ther then the bit under it cant find the variable

broken crow
#

put everything else below distnace too

sick owl
#

okay

#

like that?

broken crow
#
    return player.Character.Humanoid.Health > 0 and 
        not player:HasTag("Safezone")
end

local canChase = Check(player)

if canChase then
    local distance = (player.Character.HumanoidRootPart.Position - rootPart.Position).Magnitude
    if distance < shortestDistance then
        shortestDistance = distance
        nearestPlayer = player
    end
else
    rootPart:SetNetworkOwner(nil)
end```
sick owl
#

??

broken crow
#

yes

sick owl
#

sooo

#

i found an issue

#

for some reason i dont have the tag

#

i printed the tag for myself and there is none

#

nvm

broken crow
#

huh

sick owl
#

i just checked in player

#

i do have it

broken crow
#

yeah its not on the character

sick owl
#

its on the player yea

#

okay thats good

broken crow
#

so if you want to add anything in the future that makes it so you cant get chased, add in on the check function

sick owl
#

yea i get you

#

okay so this should work?

broken crow
#

i guess?

#

wait

#

add prints

#

so you can check

sick owl
#

i have prints for network ownershop already

#

join

broken crow
#

oh

#

i was thinking for currently checked player

sick owl
#

im already in

#

ill add them after if we are still lost

broken crow
#

k

#

wait

#

we might be on ad ifferent server

sick owl
#

we are

#

yours is the old one i think

broken crow
#

no

sick owl
#

i just rejoined

broken crow
#

its bcuz were in a different region

#

i also left

sick owl
#

huhhh

broken crow
#

roblox made a new server

#

i guess

sick owl
#

lemme join you through servers

#

hold on

broken crow
#

damn

#

i joined u 😭

sick owl
#

okay im in a new one

#

join again

broken crow
#

k

sick owl
#

so the problem is

#

that you are stil networkowner

#

when we are both in zone

broken crow
#

am i still the owner

sick owl
#

im the owner now

#

and im in the safezone

broken crow
#

oh

sick owl
#

it should be nil in zone right?

broken crow
#

yep

#

and when i died too

#

hold on

#

huh

#

now whos the owner

sick owl
#

i moved network owner to here

#

im owner rn

#

if your closer its you

#

the zone does nothing

broken crow
#

didnt it do something like 30 minutes ago

#

am i tripping

#

it does

#

you just need to be closer

sick owl
#

wdym

#

yea

#

you just need to be closer

#

now im thinking about it

broken crow
#

i think its because of the shortestDistance???

sick owl
#

yea

#

rejoin

#

i tried something

#

nbm

broken crow
#

same thing

sick owl
#

okay

#

print time

broken crow
#

if this results in nothing, you should just be focusing on the gameplay

sick owl
#

whys that

broken crow
#

cuz

#

theres currently no game

#

yk

sick owl
#

well yea

#

but i want the enemy to work

broken crow
#

well it does, just not that great

#

if youre still going to try and fix this problem, you will be demotivated by the time you make the game works

sick owl
#

okay

#

added some prints

#

rejoin

broken crow
#

should work

#

wait no

sick owl
#

okay so

broken crow
#

what print did you add

sick owl
#

current prints are like this

#

which is bad

#

so the problem is with the tag check

#

what if instead of a tag, we use an attribute?

broken crow
#

why

sick owl
#

idk, why not

broken crow
#

attribute is if you want to attach a value to it

#

like boolean, number, etc

sick owl
#

yea true or false

broken crow
#

but it will still have the same result

#

also he doesnt even chase you now

#

nvm

sick owl
#

ahhh

#

i see

#

its not finding the ta

#

read output

broken crow
#

huh

sick owl
#

i used GetTags

#

this is output

#

empty

broken crow
#

hm

#

maybe you set the tag on client?

sick owl
#

OH YEA

#

you told me to set the tag on the client

broken crow
#

what

#

where

sick owl
#

earlier on

broken crow
#

i said to kill the player on client, not set the tag

sick owl
#

after made it, you said along side some other things: "Move that over to the client"

#

i cant be bothered to go back and prove it, so just believe me on that

#

solved

broken crow
#

i also cant be bothered to check

#

ill trust u

sick owl
#

okay join

#

i put the print back for the owner

broken crow
#

k

sick owl
#

its not printing anything because it didnt get to the point where it can

#

wait

#

stop

broken crow
#

works?

#

it stops when you get here

sick owl
#

good

#

theres no player outside so he shouldnt move

broken crow
#

go outside

#

make him closer

#

then ill go

#

yeah

#

safe to say

#

it works

sick owl
#

YESS

#

all that because we had it on the client

#

we are spacs

broken crow
#

lmao

sick owl
#

wait wtf

broken crow
#

yeah ik

#

that happened to me too

sick owl
#

how

broken crow
#

because of the safezone

sick owl
#

😭

broken crow
#

but it onlly happens sometimes

#

maybe try disable CanQuery

sick owl
#

yea that might work

#

if not ill just lower it to floor level

broken crow
#

yeah

#

wait no

#

if player jumps then

sick owl
#

yea ill just have it at jump height

#

not too high

#

safe to say

#

this might be front page

broken crow
#

its taking a long time

#

true

#

are you not tired yet

sick owl
#

i am

#

its 5am

broken crow
#

oh yeah

sick owl
#

my gf has been nagging me for 3 hours

broken crow
#

weve been here for 2 hour

#

s

sick owl
#

i know lmoa

#

anyways, ill add you on discord you were chill

broken crow
#

dam

sick owl
#

wym dam

broken crow
#

nothing

sick owl
#

also found something funny

#

if you walk into the wall when your outside it gives you the tag so he stops moving

#

ill just make that smalelr and then sleep

sick owl
#

your a legend

sacred portal
#

wow

#

continue guys

#

@sick owl