Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why is this not letting me set an offset?

Asked by 8 years ago

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)
0
I got an error like this as well, and the only solution I could do is create a Variable that saves the old GUI Position, then subtract the GUI's Position by the Variable minus the Position taken off (GUI.Position = GUIVar - UDim2.new(0.1, 0, 0, 0)). :( TheeDeathCaster 2368 — 8y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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.

Ad

Answer this question