I am working on a script that changes the size of a part acoording to custom attributes, but nothing happens when trying to change size

Here is the script.

local part = script.Parent.Parte
local size = script.Parent:GetAttribute("PartSize")

script.Parent.AttributeChanged:Connect(function()
	print("change")
	wait()
	script.Parent.Parte.Size.X = size.X
	script.Parent.Parte.Size.Y = size.Y
	script.Parent.Parte.Size.Z = size.Z
end)

The “print” part does work, but the size does not change at all, is there something I am missing? Or maybe I crammed the wrong things in?

(P.S. Yes, I am using server-side testing to change the size)

Your size variable is kept constant throughout your code. When you assign a value to a variable, it will not hold a reference to the attribute – it just holds the value at the time of assignment / initialisation. It’s not like you will get the new value of the attribute from it basically

You also can’t change a vector’s components directly, since they’re immutable.You would to get the current value when the event fires by creating a variable in the event:

local part = script.Parent.Parte

script.Parent.AttributeChanged:Connect(function()
    part.Size = part:GetAttribute("PartSize")
end)
1 Like

oh yeah, I just remembered about changing the value

Quite an embarassing mistake.