17:28:12.949 ServerScriptService.CoreScripts.Move:11: Script timeout: exhausted allowed execution time - Server - MoveModule:67
17:28:12.949 Stack Begin - Studio
17:28:12.949 Script 'ServerScriptService.Modules.MoveModule', Line 67 - function AttackPerson - Studio - MoveModule:67
17:28:12.949 Script 'ServerScriptService.CoreScripts.Move', Line 11 - Studio - Move:11
17:28:12.949 Stack End - Studio
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
end
end
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(.5, 0, 0)
elseif cPositionZ > dPositionZ then
Part.Position -= Vector3.new(.5, 0, 0)
end
currentPosition = Part.Position
designatedPosition = Part2.Position
cPositionX = currentPosition.X
cPositionZ = currentPosition.Z
dPositionX = designatedPosition.X
dPositionZ = designatedPosition.Z
end
return module
As @GetGlobals stated, you should use task.wait() in order to make the script not time out. When you use a while loop without any wait time, the script will time out. If you already have it, make sure that it runs no matter what, even if any conditions are met or not.
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
end
task.wait()
end
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(.5, 0, 0)
elseif cPositionZ > dPositionZ then
Part.Position -= Vector3.new(.5, 0, 0)
end
currentPosition = Part.Position
designatedPosition = Part2.Position
cPositionX = currentPosition.X
cPositionZ = currentPosition.Z
dPositionX = designatedPosition.X
dPositionZ = designatedPosition.Z
end
return module
--\\ Module Made by Star \\--
--[[ --
MoveX:(
Part2 References The Second Part that Part1 is supposed to go to.
)
taskedLocked = Boolean that tells us if their is movement currently going on.
time = time / speed
]] --
Let’s say the distance between the two parts is over 2 studs, it will run no code because you didn’t add an else condition.
This is fine because you don’t need one, but if it runs without waiting, it will just be running simultaneously.
Let it breathe. Call task.wait() before the code in the loop runs again so the engine doesn’t crash.
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
end
task.wait()
end
Also, since you’re using the code I provided, I assume it worked; you have to mark posts as solution if they have solved your problem.