Skip to content

Commit d389c85

Browse files
Update RhythmService.lua
1 parent 269a425 commit d389c85

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

RhythmService.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ function RhythmService:AddKey(timePosition, index)
4646
end;
4747

4848
function RhythmService:SetKeys(keys)
49-
assert(typeof(keys) == "table", "keys must be a table")
49+
assert(not keys or typeof(keys) == "table", "keys must be a table or nil")
5050

5151
-- Set keys
52-
for _, timePosition in ipairs(keys) do
53-
table.insert(Song.Keys, {timePosition, 1})
52+
Song.Keys = {};
53+
if keys then
54+
for _, timePosition in ipairs(keys) do
55+
table.insert(Song.Keys, {timePosition, 1})
56+
end;
5457
end;
5558
end;
5659

@@ -60,6 +63,7 @@ function RhythmService:RemoveKey(index)
6063
end;
6164

6265
function RhythmService:CheckRhythm()
66+
assert(#Song.Keys > 0, "There has to be at least one key!");
6367
assert(Song.StopwatchEvent and Song.StopwatchEvent.Connected, "The stopwatch hasn't started!");
6468

6569
local SongPosition = Song.Sound.TimePosition;
@@ -113,8 +117,11 @@ end;
113117

114118
function RhythmService:StartStopwatch()
115119
assert(Song.Sound, "A sound hasn't been defined!");
120+
assert(#Song.Keys > 0, "There has to be at least one key!");
121+
116122
RhythmService:StopStopwatch();
117123
RhythmService:ResetKeys();
124+
Song.KeyPosition = 1;
118125

119126
-- Add a new SW
120127
Song.StopwatchEvent = RunService.Heartbeat:Connect(function()

0 commit comments

Comments
 (0)