I am currently making a flexible Moving Platform that can be changed by the user with ease.
When I run the script, it shows this.
All of the things are setup correctly (Configuration changed for the test).
Please help!
Evidences:
-- General --
local TweenService = game:GetService("TweenService")
local Platform = script.Parent.MovingPlatform
local PositionsFolder = script.Parent.Positions
local TargetPosition = script.TargetPosition
-- Configuration --
local Duration = script.Parent.Configuration:GetAttribute("Duration")
local Positions = script.Parent.Configuration:GetAttribute("Positions")
--[[ Function ]]--
local TweeningInfo = TweenInfo.new(
Duration,
Enum.EasingStyle.Quart,
Enum.EasingDirection.InOut,
0,
false,
0
)
while true do
local NewPosition = PositionsFolder:FindFirstChild(TargetPosition.Value)
local Info = {
Position = Vector3.new(NewPosition.Position)
}
local Tween = TweenService:Create(Platform, TweeningInfo, Info)
Tween:Play()
TargetPosition.Value += 1
wait(Duration)
print("Successfully completed!")
if TargetPosition.Value == Positions then
TargetPosition.Value = 1
end
wait(1)
end
The Entire Script
Library of the model.
TargetPosition is a number value.
RunScript is the main script.
Some problems were already pointed out by others, but I believe the core issue might be the fact that TargetPosition.Value isn’t set to 1 when the script first runs, which leads to FindFirstChild() returning nil.
Let me know if this works:
-- General --
local TweenService = game:GetService("TweenService")
local Platform = script.Parent.MovingPlatform
local PositionsFolder = script.Parent.Positions
local TargetPosition = script.TargetPosition
-- Configuration --
local Duration = script.Parent.Configuration:GetAttribute("Duration")
local Positions = script.Parent.Configuration:GetAttribute("Positions")
--[[ Function ]]--
local TweeningInfo = TweenInfo.new(
Duration,
Enum.EasingStyle.Quart,
Enum.EasingDirection.InOut,
0,
false,
0
)
TargetPosition.Value = 1
while true do
local NewPosition = PositionsFolder:FindFirstChild(tostring(TargetPosition.Value))
local Info = {
Position = NewPosition.Position
}
local Tween = TweenService:Create(Platform, TweeningInfo, Info)
Tween:Play()
wait(Duration)
print("Successfully completed!")
if TargetPosition.Value == Positions then
TargetPosition.Value = 1
else
TargetPosition.Value += 1
end
wait(1)
end
Also: If I understand the intention behind your configuration object, you are relying on the user entering the correct amount of positions as an attribute. You could also leave that to the script by getting the amount of position parts using #PositionsFolder:GetChildren(), thus avoiding an additional source of problems.