Script suddenly stopped working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    My script is a pathfinding scripting that can kick down doors

  2. What is the issue? Include screenshots / videos if possible!
    This script has worked for over a month.However, yesterday it suddenly stopped working

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried to look in theupdate logs but there are no changes that i did not

local pathfindingService = game:GetService("PathfindingService")
local zombie = script.Parent
local HumanoidRootPart = zombie:WaitForChild("HumanoidRootPart")
local Humanoid = zombie:WaitForChild("Humanoid")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local nearestPlayer
local PlayerFoundEvent = zombie.PlayerFound
local nextWaypoint = 2
local pathFound = false


PlayerFoundEvent.OnServerEvent:Connect(function(player)
	nearestPlayer = player
end)




repeat task.wait() until nearestPlayer ~= nil



function ComputePath()
	if nearestPlayer then
		local path: Path = pathfindingService:CreatePath({AgentCanJump = true; Costs = {Water = 10, OpenDoor = 1}})
		local success, errorMessage = pcall(function()
			path:ComputeAsync(HumanoidRootPart.Position, nearestPlayer.Character.PrimaryPart.Position)
			computed = true
		end)
		if success then
			local waypoints = path:GetWaypoints()
			for i, v: PathWaypoint in pairs(waypoints) do
				if v.Label == "OpenDoor" then
					local overlapParams = OverlapParams.new()
					overlapParams.FilterType = Enum.RaycastFilterType.Exclude
					overlapParams.FilterDescendantsInstances = {zombie}
					local place = workspace:GetPartBoundsInRadius(zombie.PrimaryPart.CFrame.Position,6,overlapParams)
					for i, v in place do
						if v.Parent.Name == "Door" then
							local base = v.Parent.Base
							local hinge = base.Parent.Doorframe.Hinge
							local prompt = base.ProximityPrompt
							local goalOpen = {}
							goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(180), 0)
							local goalClose = {}
							goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
							local tweenInfo = TweenInfo.new(1)
							local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
							if prompt.ActionText == "Open" then			
								print("Open")
								tweenOpen:Play()
								prompt.ActionText = "Close"
								v.Parent:SetAttribute("Open",true)
								base.CanCollide = false
								base.Union.CanCollide = false
							end
						end
					end
				end
				Humanoid:MoveTo(v.Position)
				nextWaypoint += 1
			end
			
		end
		if not success then
			warn(errorMessage)
		end
		
		Humanoid.MoveToFinished:Wait()
		computed = false
		if computed ~= false then return end
		ComputePath()
	end
end



ComputePath()

What is the problem?

It seems like there might be a couple of issues in your script that could be causing the problem. Here are some of my ideas which might help.

  1. Waiting for nearestPlayer: Your script starts with a repeat loop waiting for nearestPlayer to be not nil. This might cause the script to hang indefinitely if nearestPlayer is never set. Instead of a repeat loop, you might consider using a while loop with a condition to break out when nearestPlayer is set.
  2. Overlapping Parameters: You’re using OverlapParams for detecting doors, but it seems you’re using it incorrectly. GetPartBoundsInRadius doesn’t take an OverlapParams object as an argument. You should pass the OverlapParams to the method that needs it, such as workspace:FindPartsInRegion3WithIgnoreList(), which can help you identify doors within a certain radius of the zombie.
  3. Using Humanoid.MoveToFinished: You’re waiting for Humanoid.MoveToFinished, which might not be necessary in all cases. This event might not fire if the zombie is interrupted or unable to reach its destination. You could potentially encounter an issue where the script gets stuck waiting for this event.
  4. Recursive Call to ComputePath(): You’re calling ComputePath() recursively within itself. While this might work, it can lead to potential stack overflow errors if the recursion depth becomes too high. Consider using a loop instead of recursion.
  5. Variable Scoping: You’re using variables like computed without defining them in the local scope. Make sure to define these variables in the appropriate scope or as local variables within functions.
  6. Error Handling: You’re using pcall to catch errors, but you’re not handling the case where the path computation fails. Make sure to include appropriate error handling for this scenario.
  7. Event Handling: Ensure that your event handlers are properly set up and connected, especially PlayerFoundEvent.

I have done exactly as you said but it is not working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.