Scale cannot be assigned to

Hey gamers, I’m attempting to move a frame behind a button whenever the player moves their mouse over the button. I feel like there’s no reason why this shouldn’t work (I’ve rewritten it quite a few times) but I get this error that I don’t know how to solve; Scale cannot be assigned to is the entire error.

Here’s the script:

script.Parent.MouseEnter:Connect(function()
	script.Parent.Parent.Selection.Position.X.Scale = script.Parent.Position.X.Scale + 22
	script.Parent.Parent.Selection.Position.Y.Scale = script.Parent.Position.Y.Scale
end)

Here’s the hierarchy:
image

You cannot directly change the components of a Vector, instead you should do:

script.Parent.MouseEnter:Connect(function()
	script.Parent.Parent.Selection.Position = Udim2.fromScale(script.Parent.Position.X.Scale + 22, script.Parent.Position.Y.Scale)
	script.Parent.Parent.Selection.Position = Udim2.fromScale(script.Parent.Position.X.Scale, script.Parent.Position.Y.Scale)
end)
2 Likes

I get the error Players.Fox_2042.PlayerGui.Menu.Buttons.Play.LocalScript:2: attempt to index nil with 'fromScale'
Also, what’s Udim2? It’s viewed as an unknown global.

I misspelled UDim2, it’s basically a 2 dimensional vector with unique parameters.

1 Like

thanks, worked!
I’m encountering another problem though. The frame is always off to the left, and the position doesn’t change at all from changing 22 to some other number or removing it entirely. I’m not getting any errors this time though.
image

The offset is because of the +22 that you originally included in the code snippet, also you should play around with the values as they basically cancel each other out.

also you should play around with the values as they basically cancel each other out.

This was the problem, I don’t know why I didn’t realize that sooner

thanks again :3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.