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)
This is a weird bug in Roblox.
In short terms, if you insert something into the character immediately after equipping, the Equipped event will for some reason fire again.
Therefore, you get this error because the event keeps firing 'Equipped' over and over again.
See if this helps:
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) wait() On = true while On 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)