So basically, I'm trying to make a snake game and I want the snake to move in the direction of the button you pressed until you hit another key. I tried using repeat but it crashed my game so I'm not really sure where to go for there any help? My code is below ty :D
local board = game.Workspace.SnakeGame local start = game.Workspace.Start local clickdec = start.ClickDetector local UIA = game:GetService("UserInputService") local head = Instance.new("Part") clickdec.MouseClick:Connect(function(touch) head.Parent = workspace head.Position = Vector3.new(-47.935, 23.075, -57.975) head.Size = Vector3.new(2.39, 2.31, 0.05) head.BrickColor = BrickColor.new("Gold") head.Anchored = true end) UIA.InputBegan:Connect(function(touch) if touch.KeyCode == Enum.KeyCode.Space then head.Parent = game.ServerStorage end repeat if touch.KeyCode == Enum.KeyCode.W then head.Position = head.Position + Vector3.new(0, 1,0) end if touch.KeyCode == Enum.KeyCode.S then head.Position = head.Position + Vector3.new(0, -1,0) end if touch.KeyCode == Enum.KeyCode.D then head.Position = head.Position + Vector3.new(1, 0,0) end if touch.KeyCode == Enum.KeyCode.A then head.Position = head.Position + Vector3.new(-1, 0,0) end until UIA.TouchEnded end)