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

This script causes major lag for some reason, any help?

Asked by 9 years ago

So, I have a script like this:

function changed(Size)
    local a = script.Parent.Parent.Size -- script.Parent.Parent is a part
    local pos = script.Parent.Parent.position.Value -- script.Parent.Parent.position is a NumberValue
    local value = script.Parent.Parent.Value.Value -- script.Parent.Parent.Value is a Vector3Value
    local x, y, z = value.x, value.y, value.z
    value = Vector3.new(x, (pos), z)
    script.Parent.Parent.CFrame = CFrame.new(value)
end

script.Parent.Parent.Changed:connect(changed)

So, whenever I clone an object that has this script in it, the game just freezes for 5 seconds, but I have no idea why. This script is just supposed to lower a block by a certain number of studs on the y coordinate as the position value changes. When the lag clears, the script itself works fine.

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You are setting the CFrame in your function, which then triggers the Changed event again. You'll want to check that anything is different before setting the CFrame

One option is to check that the parameter Size is in fact "Size"

Ad

Answer this question