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

My stamina bar does not move the right way help?

I have created a skinny stamina bar on the side of the players screen, and when they sprint with the shift key it decreases. The problem is that the GUI is decreasing the wrong way. The bar is decreasing from bottom to top instead of top to bottom. The below code is how the bar changes while sprinting. I know this is probably an easy fix but it seems like I'm not going anywhere with it. Any help would be much appreciated

replicatedStorage.RemoteEvents.StaminaUpdate.OnClientEvent:Connect(function(stamina, maxStamina)
	players.LocalPlayer.PlayerGui.Stamina.Bar.Size = UDim2.new(0, 17, 0, (stamina / maxStamina) * 97)
end)

1 answer

✓ Accepted answer

You need to be using the X.Offset instead of the Y

Here's some sample test code I wrote to test this:

stamina = 1000
maxStamina = 1000
while wait(2) do
	
    script.Parent.Size = UDim2.new(0, (stamina / maxStamina)* script.Parent.Size.X.Offset, 0,  script.Parent.Size.Y.Offset)
	stamina = stamina - 10
	if stamina <=0 then
		stamina=maxStamina
	end
end

in your case the change would be

replicatedStorage.RemoteEvents.StaminaUpdate.OnClientEvent:Connect(function(stamina, maxStamina)
2
	    players.LocalPlayer.PlayerGui.Stamina.Bar.Size = UDim2.new(0,(stamina / maxStamina) * 17, 0,  97)
3
	end)

I like using Size.X.Offset, so i can make changes in the GUI to the size without worrying about changing hardcoded values (in your case 17 for Size.X.Offset and 97 for Size.Y.Offset.

Anyway, hope that helps.

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