Gui Animation not working

So I am aware about TweenAnimation. I am going to add that, just not yet. I have it’s size increase by 4.5 every time it goes over the + It doesn’t seem to work.

Code Block involving it (Don’t criticize the while loop, I’ve had a long day about it already and it avoids major frame drop and you don’t need to say “Use RunService!” as it lags faster.)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			game.ReplicatedStorage.PowerOccupied:FireServer(game.Players.LocalPlayer, true)
			HoldTime = tick()
			Holding = true
			workspace.Power.Sounds.PowerUP:Play()
			
			
			while task.wait(0.2) do
				if Holding == true then
					workspace.Power.Button.Color = Color3.fromRGB(0, Green, 0)
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Visible = true
					local UiSize = 0
					UiSize = UiSize + 4.5
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, 4.5, 0, 25)
					if Green == 75 then
						workspace.Power.Sounds.PowerUP2:Play()
					end
					
					if Green == 100 then
						workspace.Power.Button.Color = Color3.new(0,1,0)
						game.ReplicatedStorage.RestorePower:FireServer(game.Players.LocalPlayer)
						break
					end
					
					
					Green += 2
					print(UiSize)
					print("Color", Green)
				end
				
			end
			
		end
	end

end)

Cut version:

local UiSize = 0
UiSize = UiSize + 4.5
game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, 4.5, 0, 25)

The UiSize is not applying to the .Size.
I think your trying to do this:

game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, UiSize, 0, 25)

Tell me if it doesn’t work.

1 Like

My bad, that was a typo. This works, but one issue is it doesn’t add 4.5 to it (It goes to 100, and the size is 450 so 450 divided by 100 is 4,5). It always returns 4.5

Locate the local UiSize before the while loop.

Seems to work. But it only reaches about 60% of the way. Is it to do with AnchorPoint or such?

It is because the Green i think?
Change it to Green += 1.

1 Like

One issue is when you stop but then start again its speeded up and is off line with the rest of the stuff?
end code:

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			local GreenTransformation = workspace.Power.Button.Color.G * 255
			UiSize = 0
			game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, 0, 0, 25)
		if GreenTransformation >= 200 then
			game.ReplicatedStorage.RestorePower:FireServer()
			warn("Power restored!")
		else
			warn(workspace.Power.Button.Color.G)
		end
		HoldTime = tick() - HoldTime
		print(HoldTime)
		workspace.Power.Sounds.PowerUP:Stop()
		workspace.Power.Sounds.PowerUP2:Stop()
		Holding = false
		workspace.Power.Button.Color = Color3.new(0,0,0)
		Green = 0
		end
	end
end)

The UiSize should be before the while loop and not before the UserInputService.InputBegan.

Show me the updated start :slight_smile:

That’s when the player let’s go of the key. Not the start. It resets everything

You don’t have to put UiSize = 0 at the end. Just set the Size to 0

Show me the script :slight_smile: (charchar)

Then UiSize will remain as whatever it was when the player stopped. Once they start again, it goes straight to the old one and gets out of line.

Entire script:

local UserInputService = game:GetService("UserInputService")
local HoldTime = 0
local Holding = false
local Red = 0
local Green = 0
local Blue = 0

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			game.ReplicatedStorage.PowerOccupied:FireServer(game.Players.LocalPlayer, true)
			HoldTime = tick()
			Holding = true
			workspace.Power.Sounds.PowerUP:Play()
			
			UiSize = 0
			
			while task.wait(0.2) do
				if Holding == true then
					workspace.Power.Button.Color = Color3.fromRGB(0, Green, 0)
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Visible = true
					
					UiSize = UiSize + 4.5
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, UiSize, 0, 25)
					if Green == 75 then
						workspace.Power.Sounds.PowerUP2:Play()
					end
					
					if Green == 100 then
						workspace.Power.Button.Color = Color3.new(0,1,0)
						game.ReplicatedStorage.RestorePower:FireServer(game.Players.LocalPlayer)
						break
					end
					
					
					Green += 1
					print(UiSize)
					print("Color", Green)
				end
				
			end
			
		end
	end

end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			local GreenTransformation = workspace.Power.Button.Color.G * 255
			UiSize = 0
			game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, 0, 0, 25)
		if GreenTransformation >= 200 then
			game.ReplicatedStorage.RestorePower:FireServer()
			warn("Power restored!")
		else
			warn(workspace.Power.Button.Color.G)
		end
		HoldTime = tick() - HoldTime
		print(HoldTime)
		workspace.Power.Sounds.PowerUP:Stop()
		workspace.Power.Sounds.PowerUP2:Stop()
		Holding = false
		workspace.Power.Button.Color = Color3.new(0,0,0)
		Green = 0
		end
	end
end)

Try this

local UserInputService = game:GetService("UserInputService")
local HoldTime = 0
local Holding = false
local Red = 0
local Green = 0
local Blue = 0

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			game.ReplicatedStorage.PowerOccupied:FireServer(game.Players.LocalPlayer, true)
			HoldTime = tick()
			Holding = true
			workspace.Power.Sounds.PowerUP:Play()
			
			UiSize = 0
			
			while task.wait(0.2) do
				if Holding == true then
					workspace.Power.Button.Color = Color3.fromRGB(0, Green, 0)
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Visible = true
					
					UiSize = UiSize + 4.5
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, UiSize, 0, 25)
					if Green == 75 then
						workspace.Power.Sounds.PowerUP2:Play()
					end
					
					if Green == 100 then
						workspace.Power.Button.Color = Color3.new(0,1,0)
						game.ReplicatedStorage.RestorePower:FireServer(game.Players.LocalPlayer)
						break
					end
					
					
					Green += 1
					print(UiSize)
					print("Color", Green)
				end
			else
				break
			end
			
		end
	end

end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			local GreenTransformation = workspace.Power.Button.Color.G * 255
			--No need, because it has no UiSize to call and resets after the event finished.
			game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, 0, 0, 25)
		if GreenTransformation >= 200 then
			game.ReplicatedStorage.RestorePower:FireServer()
			warn("Power restored!")
		else
			warn(workspace.Power.Button.Color.G)
		end
		HoldTime = tick() - HoldTime
		print(HoldTime)
		workspace.Power.Sounds.PowerUP:Stop()
		workspace.Power.Sounds.PowerUP2:Stop()
		Holding = false
		workspace.Power.Button.Color = Color3.new(0,0,0)
		Green = 0
		end
	end
end)

Tell me if it doesn’t work.

And remember to add break if the Holding is false.

Heads up: Break needs to be in a loop (It breaks when its restored)

Oops.

   local UserInputService = game:GetService("UserInputService")
local HoldTime = 0
local Holding = false
local Red = 0
local Green = 0
local Blue = 0

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			game.ReplicatedStorage.PowerOccupied:FireServer(game.Players.LocalPlayer, true)
			HoldTime = tick()
			Holding = true
			workspace.Power.Sounds.PowerUP:Play()
			
			UiSize = 0
			
			while task.wait(0.2) do
				if Holding == true then
					workspace.Power.Button.Color = Color3.fromRGB(0, Green, 0)
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Visible = true
					
					UiSize = UiSize + 4.5
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, UiSize, 0, 25)
					if Green == 75 then
						workspace.Power.Sounds.PowerUP2:Play()
					end
					
					if Green == 100 then
						workspace.Power.Button.Color = Color3.new(0,1,0)
						game.ReplicatedStorage.RestorePower:FireServer(game.Players.LocalPlayer)
						break
					end
					
					
					Green += 1
					print(UiSize)
					print("Color", Green)
				else
					break
				end
			
			end
			
		end
	end

end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			local GreenTransformation = workspace.Power.Button.Color.G * 255
			--No need, because it has no UiSize to call and resets after the event finished.
			game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, 0, 0, 25)
		if GreenTransformation >= 200 then
			game.ReplicatedStorage.RestorePower:FireServer()
			warn("Power restored!")
		else
			warn(workspace.Power.Button.Color.G)
		end
		HoldTime = tick() - HoldTime
		print(HoldTime)
		workspace.Power.Sounds.PowerUP:Stop()
		workspace.Power.Sounds.PowerUP2:Stop()
		Holding = false
		workspace.Power.Button.Color = Color3.new(0,0,0)
		Green = 0
		end
	end
end)
1 Like

Works. Thank you for the help!

1 Like