I have a script for a rhythm game mechanic that’s supposed to make the arrow turn red after it passes the target, but for some reason I have a for loop that takes longer to finish than it takes to move, when it should be the same time. Why is that? The tween takes (((60/bpm)*8)/100)*130) seconds to move, and the for loop waits (((60/bpm)*8)/100) seconds 130 iterations. Here’s the code -
local rm3 = game.ReplicatedStorage.Arrow
local bpm = script.Parent.Parent:GetAttribute("bpm")
local distance = 0
if script.Parent.Name ~= "Down" then
script.Parent:TweenPosition(UDim2.new(script.Parent.Parent.GDown.Position.X.Scale, script.Parent.Parent.GDown.Position.X.Offset, script.Parent.Parent.GDown.Position.Y.Scale, script.Parent.Parent.GDown.Position.Y.Offset+30), Enum.EasingDirection.In, Enum.EasingStyle.Linear, (((60/bpm)*8)/100)*130)
for i = 0, 130, 1 do
wait(((60/bpm)*8)/100)
distance += 1
print(distance)
if distance > 100 then
script.Parent.ImageColor3 = Color3.new(1, 0, 0)
end
end
script.Parent:Destroy()
end
rm3.OnServerEvent:Connect(function(player, arrow, comp)
if comp == script.Parent.Parent.Parent.Parent.Parent.Camera and arrow == "Down" then
print(script.Parent.Position.Y)
print(script.Parent.Parent.GDown.Position.Y)
end
end)