Issue with editing a GUI through a local script

My goal is to create a script that lowers the size offset incrementally every time the animation loops.

The only issue I’m having, is for some reason when I try to change the value of the Size to a new UDim2, it doesn’t work. For clarification, the function works perfectly, and when the print line inside of the HasTag check prints, it prints the value that the new offset value should be, but in game it doesn’t actually change? Yet when I change the size offset through a non-local script it works fine…

I’ve been searching for answers for a while but cant find any similar situation the one I’m having.

Please let me know if I need to explain something better, I’m still very new to this forum.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local mouse = plr:GetMouse()
local cs = game:GetService("CollectionService")
local offset = script.Parent.Health.Size

-- Triggers when animation loops
game.ReplicatedStorage.AnimLoopedBE.Event:Connect(function(plr) 
	print("Looped")
	if cs:HasTag(mouse.Target, "Node") then
		offset = UDim2.new(offset.X.Scale,offset.X.Offset - (offset.X.Offset / mouse.Target.Hits.Value),offset.Y.Offset,offset.Y.Scale)
		print(offset.X.Offset)
	end
end)

You can’t assign to the variable by referencing it like this. Instead, it will store the current size.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local mouse = plr:GetMouse()
local cs = game:GetService("CollectionService")
local health = script.Parent.Health

-- Triggers when animation loops
game.ReplicatedStorage.AnimLoopedBE.Event:Connect(function(plr) 
	print("Looped")
	if cs:HasTag(mouse.Target, "Node") then
		health.Size = UDim2.new(health.Size.X.Scale, health.Size.X.Offset - (health.Size.X.Offset / mouse.Target.Hits.Value), health.Size.Y.Offset, health.Size.Y.Scale)
		print(health.Size.X.Offset)
	end
end)
1 Like