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

uhhh, scale cannot be assigned to??????

uh, i made a healthbar script that changes size in comparison to the players health and on the last line above end it says scale cannot be assigned to;

local player = game.Players.LocalPlayer
local health = player.Health
local Denominator = 100

wait(1)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

health.Changed:Connect(function()
	script.Parent.Frame.TextLabel.Text = health.Value .. " / " .. Denominator
	script.Parent.Frame.Size.X.Scale = health.Value / 100
end)

1 answer

✓ Accepted answer

You cannot write to individual X/Y values of the Size. The Size is a UDim2 value, and therefore you must construct a new one of such.

local xScale = health.Value / 100
local xOffset = script.Parent.Frame.Size.X.Offset
local yScale = script.Parent.Frame.Size.Y.Scale
local yOffset = script.Parent.Frame.Size.Y.Offset
script.Parent.Frame.Size = UDim2.new(xScale, xOffset, yScale, yOffset) 

1 comment

1

BRUH HOW IS THIS GUY ANSWERING EVERY QUESTION I MAKE XD

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