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

charging while dodging crashes the game?

I'm trying to make it so the user can't dodge while charging their energy. And they can't because if they try it crashes. If I press E to dodge, and press F to charge energy before the dodge script ends, is where the problem occurs. If someone could help me make it where you can't dodge while charging I would appreciate it.

uis.InputBegan:connect(function(input)--Charge
    if input.KeyCode == Enum.KeyCode.F then
        charging = true
        while charging == true do
        if dodging == false then
        game.Players.LocalPlayer.Character.Humanoid.Mana.Value = game.Players.LocalPlayer.Character.Humanoid.Mana.Value  + 1 
        wait() 
        if charging == false then return end
        if game.Players.LocalPlayer.Character.Humanoid.Mana.Value > 100 then game.Players.LocalPlayer.Character.Humanoid.Mana.Value = 100
end
end
end 
end
end)

uis.InputEnded:connect(function(input)--Stop charging
        if input.KeyCode == Enum.KeyCode.F then
        charging = false
    end
end)

dodging = false
uis.InputBegan:connect(function(input)--Dodge
    if input.KeyCode == Enum.KeyCode.E then
      if dodging == false then
          gg = Instance.new("BodyForce")
          gg.Parent = Player.Character.Torso
          gg.Force = Player.Character.Torso.CFrame.lookVector*-20000
          Player.Character.Humanoid.Jump = true 
          dodging = true
          wait(0.1)
          gg:Destroy()
  		  wait (1)
          dodging = false
		end 
	end
end)

1 answer

✓ Accepted answer

Add Wait()

At line 4 . Everytime you do a loop add a wait() Or it will make an infinite loop and it will cause the game to crash.

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