Docs should mention which properties are immutable

For example, the offsets of UDim2 can’t be assigned to, making code like this fail:

script.Parent.Bars.HealthBar.Size.X.Offset = .5

The right way to do it is to create a new UDim. This is counter intuitive to most programmers because usually you never want to allocate new objects like this if you can avoid it.

So a note here might be nice:

I forget if Vectors work the same way in Roblox Lua. The docs don’t say.

8 Likes

Every data type is immutable on Roblox. I can make it a point to add that info to each of the data types’ pages, since it’s not specified

Wouldn’t code like this fail in general since you can’t really have half a pixel?

1 Like

That sounds familiar now that you mention it.

I think the solution is for the script editor to be more self-documenting - Attempting to assign an immutable property should trigger some sort of warning in script editor

4 Likes

RaycastParams are actually a special case here for some reason, so specifically noting mutable datatypes might be a better option.

1 Like

You can, but that’s not what this code does.

3 Likes

The Offset value is in Pixels though; it would round down to 0.

I just checked in studio; creating an UDim2 with a fractional offset rounds it down.