Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i make it so there's no new inputs until the movement is done?

Asked by 2 years ago

hi! i'm relatively new to coding, especially in lua, and i'm trying to make a game that involves grid-based movement but i'm having an issue in that the player can move before the last movement is finished, which ends up leading to things like diagonal movement and basically just messing up the grid movement setup lol-- i expect this is an easy fix but i couldn't rlly find anything online to help me out here so hopefully one of u can help!

local movey = game.Workspace.PlaceholderCharacter --movey is not a permanent character name lol
local usrinpsrv = game:GetService("UserInputService")
local score = 0


usrinpsrv.InputBegan:Connect(function(input)

    --controls!! this is coded so poorly

    --forward
    if input.KeyCode == Enum.KeyCode.W then
        score = score + 1
        print(score)
        for i = 1,8 do
            movey.Position = movey.Position + Vector3.new(0, 0, -0.5)
            wait(.02)
        end

    --left
    elseif input.KeyCode == Enum.KeyCode.A then
        for i = 1,8 do
            movey.Position = movey.Position + Vector3.new(-0.5, 0, 0)
            wait(.02)
        end

--right
    elseif input.KeyCode == Enum.KeyCode.D then
        for i = 1,8 do
            movey.Position = movey.Position + Vector3.new(0.5, 0, 0)
            wait(.02)
        end

    elseif input.KeyCode == Enum.KeyCode.S then
        score = score - 1
        print(score)
        for i = 1,8 do
            movey.Position = movey.Position + Vector3.new(0, 0, 0.5)
            wait(.02)
        end     
    end
end)

also, if anybody notices anything else wrong with the script that could be fixed please let me know! ty in advance!

0
you mean only one key will work at a time so you dont want the player to move diagonally? Xapelize 2658 — 2y
0
idk how to reply to comments but to the other guy yes lol MuMuCow10008 20 — 2y

Answer this question