Script keeps timing out

I gave the exact same script above???

1 Like

Its fine, I found a fix myself.

I would incorporate your task.wait() but then I would make an else if to check if the NPC wasn’t next to the other NPC.

function module:AttackPerson(Part, Part2, speed)
	local currentPosition = Part.Position
	local designatedPosition = Part2.Position

	local cPositionX = Part.Position.X
	local cPositionZ = Part.Position.Z

	local dPositionX = designatedPosition.X
	local dPositionZ = designatedPosition.Z

	while currentPosition ~= designatedPosition do
		if (Part2.Position - Part.Position).Magnitude <= 2 then
			local DmgHighlight = Effects:WaitForChild("Highlights"):WaitForChild("Damage"):Clone() DmgHighlight.Parent = Part2 DmgHighlight.Adornee = Part2

			local Health = Part2:GetAttribute("Health")
			local Weapon = Part:GetAttribute("Weapon") if Weapon == "Fist" then
				Part2.Position -= Vector3.new(math.random(-8, 8), 0, math.random(-8, 8))
				Health -= math.random(2,4)
				Part2:SetAttribute("Health", Health)
				for i = 1,8 do
					task.wait(0.01)
					task.spawn(function()
						DmgHighlight.FillTransparency += .1
					end)
				end
				DmgHighlight:Destroy()
			end
		elseif  (Part2.Position - Part.Position).Magnitude >= 2 then
			task.wait(.25 / speed)

			if cPositionX < dPositionX then
				Part.Position += Vector3.new(.5, 0, 0)
			elseif cPositionX > dPositionX then
				Part.Position -= Vector3.new(.5, 0, 0)
			end

			if cPositionZ < dPositionZ then
				Part.Position += Vector3.new(0, 0, .5)
			elseif cPositionZ > dPositionZ then
				Part.Position -= Vector3.new(0, 0, .5)
			end

			currentPosition = Part.Position
			designatedPosition = Part2.Position

			cPositionX = currentPosition.X
			cPositionZ = currentPosition.Z

			dPositionX = designatedPosition.X
			dPositionZ = designatedPosition.Z
		end
		task.wait()
	end
end

return module

He told me it was fine if I didn’t add an else if, meaning that he eathier didn’t understand what to do, or just most likely used your script.

No offence, but just speculation.

1 Like

I am referencing the post you made prior to solve your two issues, they have been resolved and it would just make sense for you to mark as solution there.

1 Like

I stopped getting notifications from their, cause I was planning to delete is because of the lack of replies before you commented. I sent a deletion request already and stopped watching the post.

1 Like