How would I change a GUI's position based on an IntValue?

I’m trying to have a GUI’s position changed based on an IntValue, this is what I have:

MoodValue = game.Workspace.Values.KingMoodValue --is a value from 0-1 so it is compatible with the gui position

MoodValue:GetPropertyChangedSignal("Value"):Connect(function()
	local FaceIcon = script.Parent
	FaceIcon.Position = Vector2.new "{MoodValue, 0},{0.5, 0}" --this line is where the format issue is
end)

how would I format this so FaceIcon’s position is set to MoodValue?

This should work. If it doesn’t, let me know!

local MoodValue = workspace:WaitForChild("Values"):WaitForChild("KingMoodValue")

MoodValue:GetPropertyChangedSignal("Value"):Connect(function()
	local FaceIcon = script.Parent
	local Value = MoodValue.Value

	FaceIcon.Position = UDim2.new(100/Value, 0, 0.5, 0)
end)
1 Like
local FaceIcon = script.Parent
local MoodValue = workspace:WaitForChild("Values"):WaitForChild("KingMoodValue")

MoodValue.Changed:Connect(function(Mood)
	FaceIcon.Position = UDim2.new(Mood, 0, 0.5, 0)
end)

Simplified.

1 Like

That wouldn’t work, saying as the mood value could only be 0 or 1 depending on where they want the position to be. You could do the same thing with this code using a NumberValue and use a number from 0 to 1, but that’s less ethical than 0 to 100 in an IntValue.

As the original poster stated, ‘Mood’ is a value between 0 and 1.

--is a value from 0-1 so it is compatible with the gui position

If ‘Mood’ is ‘0’ 100/Value would produce ‘nan’ (not a number).

Didn’t see it lol. Wasn’t really paying attention to the notes in the code.

And my original concept was to use 100/Value since I didn’t think they’d use 0. But, I wasn’t thinking many things through lol. I’m kinda sick (covid sucks :sneezing_face:)
My brain hasn’t been working if I’m being completely honest lol