GUI bar problem

Hello, I’m begginer scripter. So far, in StarterPlayerScripts, I disabled deflaut movement and wrote code that is mouse based

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) --- Clicking Movement Code
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if mousetick == 0 then
			RunService:BindToRenderStep("move",
				-- run after the character
				Enum.RenderPriority.Character.Value + 1,
				function()
					if localPlayer.Character then
						local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
						if humanoid then
							humanoid:Move(Vector3.new(0, 0, _G.SpeedIncrease), true)   --- Enable Movement
						end
					end
				end
			)
			wait(BPM) --- Moving time 
			RunService:UnbindFromRenderStep("move") --- Disable movement
			mousetick = 1 --- Wait to end movement to allow mousebutton2 for movement action
			_G.SpeedIncrease = _G.SpeedIncrease - 0.2
		elseif mousetick == 1 then
			_G.SpeedIncrease = _G.SpeedIncrease + 0.1
		end
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		if mousetick == 1 then
			RunService:BindToRenderStep("move",
				-- run after the character
				Enum.RenderPriority.Character.Value + 1,
				function()
					if localPlayer.Character then
						local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
						if humanoid then
							humanoid:Move(Vector3.new(0, 0, _G.SpeedIncrease), true) --- Enable movement after clicking
						end
					end
				end
			)
			wait(BPM) --- running time after clicking, (per beat)
			RunService:UnbindFromRenderStep("move") --- Disable movement After clicking
			mousetick = 0
			_G.SpeedIncrease = _G.SpeedIncrease - 0.2
		elseif mousetick == 0 then
			_G.SpeedIncrease = _G.SpeedIncrease + 0.1
		end

	end
end)

I want to make GUI bar that shows SpeedIncrease
Less SpeedIncrease = higher bar.
Bar doesn’t work, I thought it was a global variable issue, so i made a text label above. That shows SpeedIncrease with 1 second refreshing time


bar code (doesn’t work)

local object = script.Parent
object.AnchorPoint = Vector2.X(0)
local size = 0 - _G.SpeedIncrease

while true do
	object.Size = UDim2.new(size, 0, 1, 0)
	wait(0.5)
end

I’ve been dealing with this problem for too long. What went wrong?

Yes its my first project in roblox, and my first post on devforum, so far i made it with devforum posts and roblox tutorials it is great community.

The size variable is outside the scope of the while loop, so it only updates right away and never checks _G.SpeedIncrease again. Change the while loop to this:

while wait(0.5) do
	size = 0 - _G.SpeedIncrease
	object.Size = UDim2.new(size, 0, 1, 0)
end

it doesn’t really change anything, but thank you for your reply.

Ensure that the bar you are trying to change is visible and not the same color as the background.

It also seems you are trying to change the vertical size of the bar so the UDim2.new should be (1,0,size,0) as the first two are x axis and the second two are y axis.

yes, I have tried that, background is black, I tried to use size on al UDim2.new numbers

Make the output visible by clicking the view tab at the top of studio and looking for output. Then run your code and check for any red text that appears in the output relating to the script. If no red text appears add a print statement within the while loop such as: print("The size is: "..tostring(size)), run the code and check to make sure the size is updating properly in output.

PlayerGui.SpeedBar.Background.Speeddisplay.Speeddisplaycode:2: attempt to call a nil value - Client - Speeddisplaycode:2

Why did that work on text label then?

local textLabel = script.Parent

while true do
	textLabel.Text = _G.SpeedIncrease
	wait(1)
end

Can I see your file structure (a layout of how the GUI and scripts are organized within Explorer)?

image
it was in one screen GUI sooner, but one tutorial said it was wrong

Don’t know how I missed this but you formatted a Vector2 wrong, it should be:
object.AnchorPoint = Vector2.new(0,0)
But this line is redundant then because the default for Anchor Point is already 0,0. See if that works then mess around with the AnchorPoint to get your desired result.

1 Like

You are great! Thank you for your support.

1 Like