I've tried using Lerp on multiple codes and got the same error message:
maximum event re-entrancy depth exceeded
Here's one of the codes (deleted others)
local player = game.Players.LocalPlayer
local Tool = script.Parent.Parent
local body = player.Character
local mouse = player:GetMouse()
--Head = script.Parent.Parent.Parent.Character.Head
xSway = 0.1
ySway = 0.1
maxX = 0.35
maxY = 0.35
smooth = 3.0
Tool.Equipped:connect(function(mouse)
On = true
while On == true do
wait()
local LocPosX = script.Parent.CFrame.X --script.Parent.Gun.CFrame.X --body.Torso.Neck.CFrame.lookVector
local LocPosY = script.Parent.CFrame.Y --script.Parent.Gun.CFrame.Y
local LocPosZ = script.Parent.CFrame.Z --script.Parent.Gun.CFrame.Z
local LocPos = script.Parent.CFrame.p --script.Parent.Gun.CFrame.p
fx = body.Head.CFrame.lookVector.x * xSway
fy = body.Head.CFrame.lookVector.y * ySway
if fx > maxX then
fx = maxX
end
if fx > -maxX then
fx = maxX
end
if fx > maxY then
fx = maxY
end
if fx > -maxY then
fx = maxY
end
local detection = Vector3.new(LocPosX + fx,LocPosY + fy, LocPosZ)
script.Parent.Position = LocPos:Lerp( detection,tick() * smooth)
end
Tool.Unequipped:connect(function(mouse)
On = false
end)
end)

1 comment
I don't know if a user could equip and then unequip within 1/30th of a second, but just in case, I'd recommend putting the "On = true" line before the "wait()" command