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

Are there any tutorials about controlling model movement with keys?

Asked by 6 years ago
Edited 6 years ago

I mean like remote control cars or something. This isn't a request, I just need to be pointed in the right direction. I wrote this script based on a page from the wiki and it technically works, but the movement is choppy.

local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer


player.CharacterAdded:Wait()

for i, v in pairs(game.Workspace.Tanks:GetChildren()) do
    if v:FindFirstChild("Owner") and v:FindFirstChild("Owner").Value == player.Name then
        tank = v
        moveVector = v.Base.Position
    end
end

userInputService.InputBegan:connect(function(inputObject)
    if player.Character then
        if inputObject.KeyCode == Enum.KeyCode.A then
            holdingA = true
            while holdingA do
                moveVector = moveVector + Vector3.new(0,0,-1)
                wait()
            end
        end
        if inputObject.KeyCode == Enum.KeyCode.D then
            holdingD = true
            while holdingD do
                moveVector = moveVector + Vector3.new(0,0,1)
                wait()
            end
        end

    end
end)

userInputService.InputEnded:connect(function(inputObject)
    if player.Character then
        if inputObject.KeyCode == Enum.KeyCode.A then
            holdingA = false
            moveVector = moveVector + Vector3.new(0,0,1)
        end
        if inputObject.KeyCode == Enum.KeyCode.D then
            holdingD = false
            moveVector = moveVector + Vector3.new(0,0,-1)
        end
    end
end)

runService.RenderStepped:connect(function()
    tank:MoveTo(moveVector)
end)

0
You can try welding. Other than that I'm in the dark MakeYourEscape 334 — 6y

Answer this question