Answered by
4 years ago Edited 4 years ago
Hello there.
Issue:
The while loop would immediately stop CobatEnabled
would be false so the while loop wouldn't run.
Fix:
Use a while true do loop checking if combat is enabled.
Improvments:
Don't use break
on the while loop if the combat isn't enabled.
Use coroutines instead of spawn
as spawn has a built-in delay.
Use game:GetService() with the Players service.
Fixed code:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local Player = game:GetService( "Players" ).LocalPlayer |
04 | local CombatEnabled = false |
06 | UserInputService.InputBegan:Connect( function (Input,IsTyping) |
08 | if Input.KeyCode = = Enum.KeyCode.E then |
14 | coroutine.wrap( function () |
17 | if CombatEnabled = = true then |
19 | print ( "Combat Enabled!" ) |
22 | print ( "Combat Disabled" ) |
Please accept and upvote this answer if it helps!