Hello, I have a problem I get this error on line 18 "Connected can not be assigned to" what I'm trying to do is that when the npc is made to the player, change the status and disconnect the RemoteEvent. What am I doing wrong?it is a nomal script and it is inside the npc Thank you.
local PatrolWalkPause = game.ReplicatedStorage.PatrolWalkPause
local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local enemy = script.Parent
local humanoid = enemy.Humanoid
local humanoidRootPart = enemy.HumanoidRootPart
local pointA = script.Parent.Parent.Start
local pointB = script.Parent.Parent.Finish
local currentDestination = pointA
Players.PlayerAdded:Connect(function(player)
if player.Character ~= nil then
while true do
local mag = (enemy.Head.Position - player.Character.PrimaryPart.Position).magnitude
print(mag)
if mag <= 50 then
conecction:Disconnect()
else
conecction.Connected = true
end
wait()
end
end
end)
conecction = PatrolWalkPause.OnServerEvent:Connect(function(patrol)
while wait(2) do
local startingPosition = humanoidRootPart.Position
local goalPosition = currentDestination.Position
local path = PathfindingService:FindPathAsync(startingPosition, goalPosition)
local waypoints = path:GetWaypoints()
for waypointIndex, waypoint in pairs(waypoints) do
local waypointPosition = waypoint.Position
humanoid:MoveTo(waypointPosition)
humanoid.MoveToFinished:Wait()
end
if currentDestination == pointA then
currentDestination = pointB
else
currentDestination = pointA
end
end
end)

5 comments
You're defining "conecction" after you do functions on it, that doesn't work. You'd need to define conecction above the PlayerAdded function. Also, you can't set "conecction.Connected" since it's not a property of a RBXScriptConnection.
What are you trying to do here: [conecction.Connected = true] If you don't want to disconnect the connection you don't have to do anything. As the errors states you can't assign to Connected, it's a read only value.
Thank you
Then when it leaves the disconnection will it automatically connect?
And this kind of script where do you have to go?