Hello there. I will try to make this as short as possible. Basically, I have this flag (FlagModel) and two extra bricks which indicate positions (UpPosition and DownPosition). I also have an IntValue
which is called Percentage. This value holds numbers from 0 to 100.
What I am trying to do is whenever the Percentage value is changed, if the value is 50% or less, then it will position the flag where it should be positioned based on the percentage. Also, the flag is going from the UpPosition to the DownPosition. For example, if the percentage is 45%, then the flag should be 90% done reaching the DownPosition, so it would be close to the DownPosition. If the percentage is 10% on the other hand, the flag should be 20% done reaching the DownPosition, so it would be close to the UpPosition, and so on.
I can easily get that percentage (you can simply do Percentage.Value * 2), but I can’t get the overall math right in order to position it where it’s supposed to be. It seems to be somewhat working because it does go from the top to the bottom, it just does it the moment the percentage is 1%, so I am guessing something is wrong with the final CFrame value. Here is the code:
local Success4, ErrorMessage4 = coroutine.resume(coroutine.create(function()
Percentage.Changed:connect(function(Change)
if Percentage.Value =< 50 then
local PercentageNumber = Percentage.Value
local PercentageValue = ((PercentageNumber * 2) * 0.01)
local A = (UpPosition.CFrame - DownPosition.Position)
local B = Vector3.new(0, PercentageValue, 0)
local C = (A * B)
local NewCFrame = CFrame.new(UpPosition.Position - C)
local Tween = TweenService:Create(FlagModel, TweenInfo.new((TimeToClaim / 100), Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {CFrame = NewCFrame})
Tween:Play()
end
end)
end))
Also, here is footage of the code somewhat working:
If you could help, that would be amazing. Thank you for your time.