Getting frames to drop at specific tempos

I’m trying to create a basic rhythm based game. All I want is tiles to fall down on like beats 1, 2, 3, 4. Not really trying to do advanced rhythms or held notes, that’s too hard for me.

So if I have the BPM of a song at 126, so 126/60 would mean 2.1 notes a second. 4 notes in a bar, 0.525 seconds between each note. wait(0.525) doesn’t work. Also trying to incorporate multiple notes on the screen isn’t working either

local function createTile(tileDirection, timer)
	TilePosition = Bottom:FindFirstChild(tileDirection)
	if not TilePosition then return end
	
	local Tile = Instance.new('ImageButton')
	Tile.AnchorPoint = Vector2.new(0.5, 0.5)
	Tile.BackgroundTransparency = 1
	Tile.Name = TilePosition.Name
	Tile.Position = UDim2.new(TilePosition.Position.X.Scale, 0, -3, 0)
	Tile.Size = UDim2.new(0.2, 0, 1, 0)
	Tile.Image = 'http://www.roblox.com/asset/?id=4494490867'
	
	if tileDirection == 'Up' then
		Tile.Rotation = 90
	elseif tileDirection == 'Right' then
		Tile.Rotation = 180
	elseif tileDirection == 'Down' then
		Tile.Rotation = 270
	end
	
	local AspectRatio = Instance.new('UIAspectRatioConstraint')
	
	AspectRatio.Parent = Tile
		
	Tile.Parent = Scrolling
	
	CurrentTile = Tile
	
	local TileIndex = #Tiles + 1
	Tiles[TileIndex] = {Tile, tileDirection}

	spawn(function()
		Tile:TweenPosition(UDim2.new(TilePosition.Position.X.Scale, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, timer, true, function()	
			if not GameRunning then
				DanceMinigame:StopGame()
				Scrolling:ClearAllChildren()
				
				return
			end
	
			if Scrolling:FindFirstChild(Tile.Name) then
				giveMiss()
				Tile:Destroy()
			end
		end)	
	end)
end

local function checkPosition()
	if Debounce then return end
	
	Debounce = true
	
	local BottomTile = Bottom:FindFirstChild(CurrentTile.Name)
	
	
	if Tiles[1][1] == CurrentTile then
		
				
	if CurrentTile.Position.Y.Scale < 0.7 and CurrentTile.Position.Y.Scale > 0.3 then
		local ScorePoints = 0
		if CurrentTile.Position.Y.Scale < 0.55 and CurrentTile.Position.Y.Scale > 0.45 then
			Note.TextColor3 = Color3.fromRGB(29, 252, 255)
			Note.Text = 'PERFECT'
			
			ScorePoints = 5
			BottomTile.ImageColor3 = Color3.fromRGB(29, 252, 255)
		elseif CurrentTile.Position.Y.Scale < 0.6 and CurrentTile.Position.Y.Scale > 0.4 then
			Note.TextColor3 = Color3.fromRGB(79, 255, 114)
			Note.Text = 'GREAT'	
			
			ScorePoints = 3
			BottomTile.ImageColor3 = Color3.fromRGB(79, 255, 114)
		else
			Note.TextColor3 = Color3.fromRGB(252, 199, 255)
			Note.Text = 'OK'
			
			ScorePoints = 1
			BottomTile.ImageColor3 = Color3.fromRGB(252, 199, 255)
		end
		
		Combo = Combo + 1
		
		if Combo >= 10 then
			ComboLabel.Text = 'COMBO ' .. Combo
			
			local RoundedCombo = math.floor((Combo / 2) + 0.5)
			ScorePoints = ScorePoints + RoundedCombo
		end
		
		Score = Score + ScorePoints
		
		ScoreLabel.Text = 'Score: ' .. Score
		
		spawn(function()
			createScoreLabel(ScorePoints, BottomTile)
		end)
		
		Note:TweenSize(UDim2.new(0.8, 0, 0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25, true, function()
			Note:TweenSize(UDim2.new(0.7, 0, 0.4, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.25, true)
		end)
		
		BottomTile:TweenSize(UDim2.new(0.25, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.05, true)
		
		CurrentTile:Destroy()
		table.remove(Tiles, 1)
	else
		giveMiss(BottomTile)
	end
	
	wait(0.05)
	
	if BottomTile then
		BottomTile:TweenSize(UDim2.new(0.2, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.05, true)
	end
	
	BottomTile.ImageColor3 = Color3.fromRGB(255, 255, 255)
	
	end
	
	wait(0.5)
	
	Debounce = false	
end

for i, v in pairs(Tracks[track].Track) do
		if not GameRunning then
			DanceMinigame:StopGame()
			Scrolling:ClearAllChildren()
			
			return
		end
		
		createTile(v, Tracks[track].Speed)
		wait(0.525)
	end

When I press the key it is trying to destroy the newest frame, not the oldest one

robloxapp-20191221-2229517

1 Like