I know what I said above is probably a little confusing, but its hard to explain.
I’m trying to make a block that moves with WASD, and it works but I want it to keep going forward if I hold the key down (sort of like how your roblox player moves constantly forward when you press any of the WASD keys). The block is only moving once so you have to spam press the keys.
(heres an example)
block.wmv (1.4 MB)
(and heres the code)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local db = false
local uis = game:GetService("UserInputService")
local movingPart = game.Workspace.MovingPart
script.Parent.MouseButton1Click:Connect(function()
if db == false then
db = true
else
db = false
end
end)
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.W and db == true then
movingPart.Position = movingPart.Position + Vector3.new(0,0,1)
elseif uis:IsKeyDown(Enum.KeyCode.A) and db == true then
movingPart.Position = movingPart.Position + Vector3.new(-1,0,0)
elseif input.KeyCode == Enum.KeyCode.S and db == true then
movingPart.Position = movingPart.Position + Vector3.new(0,0,-1)
elseif input.KeyCode == Enum.KeyCode.D and db == true then
movingPart.Position = movingPart.Position + Vector3.new(1,0,0)
end
end)
(in case your curious what the mousebutton1click is about, i made it so it will only start moving when you press a button)
Any help appreciated!