i am getting "Offset cannot be assigned to" on line 12 and I dont know what is wrong
I am trying to make a custom health system and it worked up until I tried making the rads (Radiation from fallout) remove from your total health when it reached the same point as your total (make it so that the rad is always the max it can be filled)
Here is the health bar without rads: https://gyazo.com/82168c6511258c544ad3b5ae690c3600
A red line from the end closest the the center will appear when there is at least one rad(s).
it uses remote events so it can fire from anywhere, the scripts that fire it dont have any issue its only when I try lowering the health I have an issue.
This is the layout of the game from StarterGui: https://gyazo.com/0494c3fd3e7574fb9f06cc6b447ec629
and yes it works from startergui because I am getting the remoteEvent fired on hit with hit.Name being the player
Code:
x = 0 y = 0 script.RemoteEvent.OnServerEvent:connect(function() x = x - 1 y = y + 1 if (script.Parent.Parent.Health.size.X.Offset == script.Parent.Size.X.Offset + 250) then print ("same") print(y) script.Parent.Parent.Health.healthVal.Value = script.Parent.Parent.Health.size.X.Offset script.Parent.Parent.Health.Size.X.Offset = script.Parent.Parent.Health.size.X.Offset - y end script.Parent.RadVal.Value = script.Parent.RadVal.Value + 1 script.Parent.Size = UDim2.new(0,x,1,0) end)
You aren't able to modify the pieces of a UDim2
. UDim2s represent values, and so position (0, 1, 2, 3) is always position (0, 1, 2, 3) -- it can't be changed to something else.
If you want to change the Size, you have to change the size -- you can't change a piece of iot.
health.Size = health.Size - UDim2.new(0, y, 0, 0)
(I really recommend making a health = script.Parent.Parent.Health
variable instead of repeating yourself over and over)
I think it's sort of weird that you have x
and y
even though x
is just a negative version of y
... you don't really need both.