Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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"

This discussion is preserved as it was. New answers, comments, and votes are closed.