What do you want to achieve? Keep it simple and clear!
I want to make a Tween when player hits both W and D keys and turns back into the same position when stop pressing the keys. (InputBegan working but InputEnded isn’t working.)
What is the issue? Include screenshots / videos if possible!
It doesn’t detect anything when I stop pressing W and D keys. (not prints the text too.)
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input, gpe) --Working
if gpe then return end
if userInputService:IsKeyDown(Enum.KeyCode.W) and userInputService:IsKeyDown(Enum.KeyCode.D) then
Angle = -25
Tween0C0()
TweenC0()
Tween1C0()
Tween2C0()
script.sound:Play()
print("DW 1")
end
end)
userInputService.InputEnded:Connect(function(input, gpe) --Not working
if gpe then return end
if userInputService:IsKeyDown(Enum.KeyCode.W) and userInputService:IsKeyDown(Enum.KeyCode.D) then
Angle = 0
Tween0C0()
TweenC0()
Tween1C0()
Tween2C0()
script.sound:Play()
print("DW 0")
end
end)
That’s because when you stop pressing w, well the key isn’t down anymore so the IsKeyDown will return false and it won’t run your code. It will run if you press an extra key that isn’t W or D while you’re holding W and D, but I don’t think that is what you want. Your code doesn’t make sense, so you want to check if input is W then also check if D is down (inside the inputended connection). If input is D then check if W is also down and then run your tweens.
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input, gpe) --Working
if gpe then return end
if userInputService:IsKeyDown(Enum.KeyCode.W) and userInputService:IsKeyDown(Enum.KeyCode.D) then
Angle = -25
Tween0C0()
TweenC0()
Tween1C0()
Tween2C0()
script.sound:Play()
print("DW 1")
end
end)
userInputService.InputEnded:Connect(function(input, gpe) --Not working
if gpe then return end
if (userInputService:IsKeyDown(Enum.KeyCode.W) and input.KeyCode == Enum.KeyCode.D) or (userInputService:IsKeyDown(Enum.KeyCode.D) and input.KeyCode == Enum.KeyCode.W) then
Angle = 0
Tween0C0()
TweenC0()
Tween1C0()
Tween2C0()
script.sound:Play()
print("DW 0")
end
end)