Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Vector3:Lerp not working?

Asked by
Exsius 162
9 years ago

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 answer

Log in to vote
4
Answered by 9 years ago

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)

0
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 chess123mate 5873 — 9y
Ad

Answer this question