I just made my first line of code as a developer! I just want to know. Does it seem to basic, to complexe? What did I do wrong? What could I do to make it more efficient?
local UIS = game:GetService(“UserInputService”)
local player = game.Players.LocalPlayer
local PlayersService = game:GetService(“Players”)
local LocalPlayer = PlayersService.LocalPlayer
wait(5)
UIS.InputBegan:Connect(function(input,gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.R then
wait(1)
local Character = LocalPlayer.Character
print(“Player started pressing R”)
Character.Humanoid.Health = 0
end
end)`
Why do you wait 5 seconds before the code runs, and then wait 1 second inside the InputBegan function? I would suggest getting rid of the waits. Also, make sure that the character actually exists inside of the InputBegan function.
The wait was there because at first I was trying to use a while loop and just forgot to remove the wait. I will remove the first wait. The second one for some reason reduced lag in my studio when I pressed “R”.