(Kinda big. Take your time). Power station restore requires 2 restores, not 1 (Intending 1, and decides to want 2)

Hello! The past few days a few of you have helped me finish a project I never thought would be this hard, but this probably is the last time I post about this. This is sort of big, so make sure you read everything before making a judgement etc.

The hold-e-to-fix-local-script-o
Independent (Nothing else is in the script excluding given code) = true

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

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if (game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true and DB == false and workspace.Power.Button:GetAttribute("CanReStore") == true) then
			DB = true
			game.ReplicatedStorage.PowerOccupied:FireServer(game.Players.LocalPlayer, true)
			HoldTime = tick()
			Holding = true
			workspace.Power.Sounds.PowerUP:Play()

			local UiSize = 0

			while Holding == true do
					workspace.Power.Button.Color = Color3.fromRGB(0, Green, 0)
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Visible = true

					UiSize = UiSize + 4.5
					
					local TweenGuiSize = game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar:TweenSize(
						UDim2.new(0, UiSize, 0, 25),
						Enum.EasingDirection.Out,
						Enum.EasingStyle.Linear,
						0.1,
						true
					)
					game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar.Size = UDim2.new(0, UiSize, 0, 25)
					if Green == 75 then
						workspace.Power.Sounds.PowerUP:Stop()
						workspace.Power.Sounds.PowerUP2:Play()
					end

					if Green == 100 then
						
						Green = 0
						workspace.Power.Button.Color = Color3.new(0,1,0)
						game.ReplicatedStorage.RestorePower:FireServer(game.Players.LocalPlayer)
						game.Players.LocalPlayer.PlayerGui.PointsGui.PointsGained.Text = "Gained 50 Points!"
						game.Players.LocalPlayer.PlayerGui.PointsGui.PointsGained.Visible = true
						workspace.Power.Sounds.PowerUP:Stop()
						workspace.Power.Sounds.PowerUP2:Stop()
						task.wait(1)
						game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Visible = false
						task.wait(2)
						game.Players.LocalPlayer.PlayerGui.PointsGui.PointsGained.Visible = false
						game.Players.LocalPlayer.PlayerGui.PointsGui.PointsGained.Text = "Gained (Points)"
						warn("Ending")
						Holding = false
					end
					warn("Didn't end")
				Green += 1
				task.wait(0.1)
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if game.Players.LocalPlayer:GetAttribute("CanRestorePower") == true then
			Holding = false
			workspace.Power.Button.Color = Color3.new(0,0,0)
			Green = 0
			local GreenTransformation = workspace.Power.Button.Color.G * 255
			local TweenGuiSize = game.Players.LocalPlayer.PlayerGui.PowerGui.Restoring.Bar:TweenSize(
				UDim2.new(0, 0, 0, 25),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Linear,
				0.5,
				true
			)
			if GreenTransformation >= 100 then
				game.ReplicatedStorage.RestorePower:FireServer()
			end
			workspace.Power.Sounds.PowerUP:Stop()
			workspace.Power.Sounds.PowerUP2:Stop()
			task.wait(3)
			DB = false
		end
	end
end)

The restore-current-power-scrip-to
Independent (Nothing else is in the script excluding given code) = true

game.ReplicatedStorage.RestorePower.OnServerEvent:Connect(function(playerWhoEnabled)
	
	for index, value in pairs(game.Players:GetPlayers()) do
		local CharacterEnsure = value.Character or value.CharacterAdded:Wait()
		local Character = value.Character
		
		Character:WaitForChild("ShowPowerStationRestore").Disabled = true
	end
	game.ServerScriptService.Power.PowerRemoving.Disabled = false
	game.ServerStorage.Power.Gui.PersonWhoRestored.Value = playerWhoEnabled
	game.ServerStorage.Power.Gui.CanMessageOn.Value = true
	game.ServerStorage.Power.Gui.CanMessageOn.Value = true
	game:GetService("ServerStorage").Power.PowerOn.Value = true
	workspace.Power.Button.BillboardGui.Enabled = false
	playerWhoEnabled.leaderstats.Points.Value += 50
	game.ServerStorage.Power.CurrentPower.Value = game.ServerStorage.Power.MaxPower.Value
	print(game.ServerStorage.Power.CurrentPower.Value)
	workspace.Power.Button.BillboardGui.Enabled = false
	workspace.Power.Shock.DamageScript.Disabled = false
	workspace.Power.Shock.Transparency = 0.7
	workspace.Power.Shock.CanCollide = true
	task.wait(0.5)
	print(game.ServerStorage.Power.CurrentPower.Value)
end)

Thanks a lot everyone. I've been trying my hardest the past few days about this and I am still learning. Thanks for helping!
1 Like

Add this to both Inputbegan and InputEnded:

UserInputService.InputBegan:Connect(function(input,gmp)

--This one
   if gmp then
      return
   end

To check if the player was chatting or on the settings when pressing the key.

Instead of using == true on conditionals,
try if DB then (To check if true) or if not DB then(To check if false).

The game.ServerStorage.Power.Gui.CanMessageOn.Value = true on the second script is doubled.

This is just my opinion, but I hope this helps :slight_smile:

Also congrats!

2 Likes

Ah thanks for the first one! I seemed to of forgot about that.
The second one is kind of confusing. So what do i make the condition?
Third one is good too. I didn’t notice it. Thanks!

2 Likes

The second one for conditions are the shortened for bool conditions.

Example:

if DB == true then
   print("Hey!") 
end

Shortened ver.

if DB then
   print("Hey!")
end

They are the same but without the == true.

Same thing to false.

Example:

if DB == false then
   print("Hey!") 
end

Shortened ver.

if not DB then
   print("Hey!")
end

This is just my preferences.

2 Likes

Ah okay. After putting in the GameProccessed parameter and doing return end if its true, it still appears to be doing the same thing. Any other things that might help?

UserInputService will activate even if the person is on chat. Adding gmp will make the key not activate when the player is on chat.

Ik. I already added that part. Is there anything else tho that may fix it?

Try changing that to:

repeat
   --The code
until not Holding

Seems to have no difference. It’s a bit weird?

I’m just changing some parts of the scripts. It’s still working the same.
Your script is already good for me :slight_smile:

Okay. But do you have a solution? Thanks for helping tho.
Here’s a video:
robloxapp-20220115-2243570.wmv (5.5 MB)

Oh, so this is the problem, It doesn’t work for the first time?

Yes. It’s kind of strange? It was working before.

Can you show the output? (charrrr)

It’s full of print and debugging stuff. It show’s no error but a good keypoint is how i added a warn to the repeat loop when it ends and it goes twice (May of changed since i was using a while loop when i put it in, not a repeat)

Add break after the warn("Ending").
Tell me if it works.

1 Like

It turns Holding to false but I can tell what you mean. I’ll put it after that.

Still no. The way I ensure it doesn’t work is by disabling the script for every character. I noticed that on the 1st try the script doesn’t disable but on the 2nd it does.

Try adding prints on some parts of the scripts to ensure its working.

I already did that before. Everything seems to be working, I think it may be to do with disabling the script that disables the main part.