I am making a ping pong game and the problem I’m facing is how to make the bar that the player uses to hit the ball work. Basically it needs to go up and down when you press W,S or up arrow,down arrow.
Any way to create a script like this?
I am making a ping pong game and the problem I’m facing is how to make the bar that the player uses to hit the ball work. Basically it needs to go up and down when you press W,S or up arrow,down arrow.
Any way to create a script like this?
You would do something like this:
local Frame = script.Parent:WaitForChild("Frame") --// Set this as the path of the frame you want to move
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, Processed)
if (Processed) then return end
if (Input.KeyCode == Enum.KeyCode.W) or (Input.KeyCode == Enum.KeyCode.Up) then
repeat
Frame.Position += UDim2.new(0, 0, 0, 2) --// Makes the frame go up by 2 pixels
task.wait()
until (UIS:IsKeyDown(Input.KeyCode) == false)
elseif (Input.KeyCode == Enum.KeyCode.S) or (Input.KeyCode == Enum.KeyCode.Down) then
repeat
Frame.Position -= UDim2.new(0, 0, 0, 2) --// Makes the frame go down by 2 pixels
task.wait()
until (UIS:IsKeyDown(Input.KeyCode) == false)
end
end)