I made a tween script to automatically send an arrow via a beem to the next checkpoint to show where the player is supposed to go in the obby, but I wanted to add when this tween isn’t playing (not moving to the next checkpoint) to play another tween on loop of the arrow moving up and down about 2 studs.
I’m having a very hard time implementing this into my script; any help is immensely appreciated.
Thanks in advance.
Script:
local TweenService = game:GetService("TweenService")
local Object = game Workspace.Pointer["1"]
local Object2 = game.Workspace.Pointer["0"]
local tweenInfo = TweenInfo.new(
0.4, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style.
Enum.EasingDirection.InOut, -- EasingDirection
0, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
false, -- Reverse
0 -- Delay
)
game.Players.LocalPlayer:WaitForChild('leaderstats',math.huge):WaitForChild('Stage'):GetPropertyChangedSignal("Value"):Connect(function()
local Stage = game.Players.LocalPlayer:WaitForChild('leaderstats',math.huge):WaitForChild('Stage')
local NextStage = workspace.Checkpoints:FindFirstChild(Stage.Value+1)
local NextStagePos = NextStage.Position
local Tween = TweenService:Create(Object, tweenInfo, {Position = NextStagePos + Vector3.new(0,1,0)})
local Tween2 = TweenService:Create(Object2, tweenInfo, {Position = NextStagePos + Vector3.new(0,14,0)})
Tween:Play()
Tween2:Play()
end)
Because tweens overwrite eachother when called, I think this is could be easier than you think.
Here’s some psuedo-code to show what I mean:
local IdleTweenInfo = TweenInfo.new( _, _, _, -1 true, _) --these values are mandatory
IdleTween:Play()--kickstarts the idle tween
PropertyChangedSignal:Connect(function()
MoveToNextCheckpointTween:Play()--play the tween to the next checkpoint
MoveToNectCheckpointTween.Completed:Wait()--wait for it to complete
IdleTween:Play()--restarts the idle tween, loop infinitely
end)
Tween:Play()
Tween1Plays = true
Tween.Completed:Connect(function()
Tween1Plays = false
end)
while true do
wait(1)
if Tween1Plays == false then
Tween2:Play()
end
end
This solution seems to work in theory, but when I tried it, it didn’t work. (non of the tweens are working)
Maybe I made an error??
local TweenService = game:GetService("TweenService")
local Object = game.Workspace.Pointer["1"]
local Object2 = game.Workspace.Pointer["0"]
local tweenInfo2 = TweenInfo.new(
0.4, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style.
Enum.EasingDirection.InOut, -- EasingDirection
-1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
false, -- Reverse
0 -- Delay
)
local tweenInfo = TweenInfo.new(
0.4, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style.
Enum.EasingDirection.InOut, -- EasingDirection
1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
true, -- Reverse
0 -- Delay
)
local IdleTween1 = TweenInfo.new(Object, tweenInfo2, {Position = Object.Position + Vector3.new(0,1,0)})
local IdleTween2 = TweenInfo.new(Object2, tweenInfo2, {Position = Object2.Position + Vector3.new(0,1,0)})
IdleTween1:Play()
IdleTween2:Play()
game.Players.LocalPlayer:WaitForChild('leaderstats',math.huge):WaitForChild('Stage'):GetPropertyChangedSignal("Value"):Connect(function()
local Stage = game.Players.LocalPlayer:WaitForChild('leaderstats',math.huge):WaitForChild('Stage')
local NextStage = workspace.Checkpoints:FindFirstChild(Stage.Value+1)
local NextStagePos = NextStage.Position
local Tween = TweenService:Create(Object, tweenInfo, {Position = NextStagePos + Vector3.new(0,1,0)})
local Tween2 = TweenService:Create(Object2, tweenInfo, {Position = NextStagePos + Vector3.new(0,14,0)})
Tween:Play()
Tween2:Play()
Tween2.Completed:Wait()
IdleTween1:Play()
IdleTween2:Play()
end)
My Idea of the Idle Tween is to take the current position of the arrow, and tween it upwards some unit of studs, and since it reverses it will look like its bobbing. I’ve tried to make myself more clear this time.
local IdleTweenInfo = TweenInfo.new()--dont forget you can make it bob downwards instead if you wanted to
local MoveToCheckPointInfo = TweenInfo.new()
Arrow.Position = CurrentCheckpoint.Position + Vector3.new(0,1,0)--makes sures that the arrow is in its place before tweening
local IdleTween = TweenService:Create(Arrow, IdleTweenInfo, {Position = CurrentCheckPointPosition + Vector3.new(0,14,0)}) --assuming that the arrow is already placed above the first checkpoint
IdleTween:Play()
GetPropertyChangedSignal:Connect(function()
local Stage
local NextStage
local NextStagePos
local MoveToNextCheckpointTween = TweenService:Create(Arrow, MoveToCheckPointInfo, {Position = NextStagePos + Vector3.new(0,1,0)})
MoveToNextCheckpointTween:Play()
MoveToNextCheckpointTween.Completed:Wait()
IdleTween:Play()
end)
--using this method, the arrow tweens to its minimum position when going from checkpoint to checkpoint, and idles to its maximum position.You can reverse this by reversing the idletween's goal and the movingtween's goal
Also be sure the two different tweens use their own info.
Why is tweening so hard!! I’m so sorry but it’s still not working
I can’t tell if it’s on my end as there are lines in the code, but the tweening is not moving like in the last video.
heres my code
local TweenService = game:GetService("TweenService")
local IdleTweenInfo = TweenInfo.new(0.4, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style.
Enum.EasingDirection.InOut, -- EasingDirection
-1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
true, -- Reverse
0) -- Delay)--dont forget you can make it bob downwards instead if you wanted to
local MoveToCheckPointInfo = TweenInfo.new( 0.4, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style.
Enum.EasingDirection.InOut, -- EasingDirection
1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
false, -- Reverse
0)
local Arrow = game.Workspace.Pointer["1"]
local Arrow2 = game.Workspace.Pointer["0"]
local Stage = game.Players.LocalPlayer:WaitForChild('leaderstats',math.huge):WaitForChild('Stage')
local CurrentCheckPoint workspace.Checkpoints:FindFirstChild(Stage.Value)
local NextStage = workspace.Checkpoints:FindFirstChild(Stage.Value+1)
local NextStagePos = NextStage.Position
Arrow.Position = CurrentCheckpoint.Position + Vector3.new(0,1,0)
Arrow2.Position = CurrentCheckpoint.Position + Vector3.new(0,1,0)--makes sures that the arrow is in its place before tweening
local IdleTween = TweenService:Create(Arrow, IdleTweenInfo, {Position = CurrentCheckPoint.Position + Vector3.new(0,14,0)}) --assuming that the arrow is already placed above the first checkpoint
IdleTween:Play()
local IdleTween2 = TweenService:Create(Arrow, IdleTweenInfo, {Position = CurrentCheckPoint.Position + Vector3.new(0,14,0)}) --assuming that the arrow is already placed above the first checkpoint
IdleTween:Play()
game.Players.LocalPlayer:WaitForChild('leaderstats',math.huge):WaitForChild('Stage'):GetPropertyChangedSignal("Value"):Connect(function()
local MoveToNextCheckpointTween = TweenService:Create(Arrow, MoveToCheckPointInfo, {Position = NextStagePos + Vector3.new(0,1,0)})
MoveToNextCheckpointTween:Play()
MoveToNextCheckpointTween.Completed:Wait()
IdleTween:Play()
end)
I was having trouble because theres only one arrow when I have arrow 2 parts, I also dont get what you mean by “–dont forget you can make it bob downwards instead if you wanted to”??