Hello, I was recently trying to make a rythm game but this happens when I play:
It keeps on spawning a lot of arrows and chooses the same one over and over again. Here is my coide:
local player = game.Players.LocalPlayer
local uis = game:GetService('UserInputService')
local arrow = game.ReplicatedStorage.Arrow
local Main = script.Parent.Main
local runService = game:GetService('RunService')
local music = workspace["Skeletone Deaf a"]
local tweenTime = 2
local arrowTypes = {
'UP',
'Down',
'Left',
'Right',
}
function AddArrow(ArrowType)
if ArrowType == 'UP' then
local clonedArrow = arrow:Clone()
clonedArrow.Parent = Main
local posX = script.Parent.Main.Up.Position.X.Scale
local posY = script.Parent.Main.Up.Position.Y.Scale
clonedArrow.Position = UDim2.new(posX,0,1,0)
clonedArrow.ImageColor3 = script.Parent.Main.Up.ImageColor3
clonedArrow.Rotation = 180
clonedArrow:TweenPosition(UDim2.new(posX,0,-1,0), nil, nil, tweenTime)
wait(1)
clonedArrow:Destroy()
return clonedArrow
elseif ArrowType == 'Down' then
local clonedArrow = arrow:Clone()
clonedArrow.Parent = Main
local posX = script.Parent.Main.Down.Position.X.Scale
local posY = script.Parent.Main.Down.Position.Y.Scale
clonedArrow.Position = UDim2.new(posX,0,1,0)
clonedArrow.ImageColor3 = script.Parent.Main.Down.ImageColor3
clonedArrow.Rotation = 0
clonedArrow:TweenPosition(UDim2.new(posX,0,-1,0), nil, nil ,tweenTime)
wait(1)
clonedArrow:Destroy()
return clonedArrow
elseif ArrowType == 'Left' then
local clonedArrow = arrow:Clone()
clonedArrow.Parent = Main
local posX = script.Parent.Main.Left.Position.X.Scale
local posY = script.Parent.Main.Left.Position.Y.Scale
clonedArrow.Position = UDim2.new(posX,0,1,0)
clonedArrow.ImageColor3 = script.Parent.Main.Left.ImageColor3
clonedArrow.Rotation = 90
clonedArrow:TweenPosition(UDim2.new(posX,0,-1,0),nil,nil,tweenTime)
wait(1)
clonedArrow:Destroy()
return clonedArrow
elseif ArrowType == 'Right' then
local clonedArrow = arrow:Clone()
clonedArrow.Parent = Main
local posX = script.Parent.Main.Right.Position.X.Scale
local posY = script.Parent.Main.Right.Position.Y.Scale
clonedArrow.Position = UDim2.new(posX,0,1,0)
clonedArrow.ImageColor3 = script.Parent.Main.Right.ImageColor3
clonedArrow.Rotation = -90
clonedArrow:TweenPosition(UDim2.new(posX,0,-1,0),nil,nil,tweenTime)
wait(1)
clonedArrow:Destroy()
return clonedArrow
end
end
runService.RenderStepped:Connect(function()
wait(1)
local ChosenArrow = math.clamp(music.PlaybackLoudness/20,1,#arrowTypes)
AddArrow(arrowTypes[ChosenArrow])
end)
Thank you!