So I want to move a random block every 3 seconds but I want the tween time to be longer so the tween need to be going at the same time after a few seconds this is my script, but is there a way to do this?
local tweenService = game:GetService("TweenService")
local killBlocksAmount = #game.Workspace.MiniGameFolder.KillBlockFolder:GetChildren()
game:WaitForChild("ReplicatedStorage"):WaitForChild("MoveBlocks"):GetPropertyChangedSignal("Value"):Connect(function()
math.random(1,killBlocksAmount)
local killBlockToMove = game.Workspace.MiniGameFolder.KillBlockFolder:FindFirstChild("KillBlock"..tostring(killBlocksAmount))
local Info = TweenInfo.new(
5,
Enum.EasingStyle.Quart,
Enum.EasingDirection.In,
0,
true,
0
)
local oldXPos = killBlockToMove.CFrame.Position.X
local oldYPos = killBlockToMove.CFrame.Position.Y
local newZPos = killBlockToMove.CFrame.Position.Z -65
local Goals =
{
Position = Vector3.new(oldXPos, oldYPos, newZPos);
Color = Color3.new(1, 0, 0)
}
local KillPartTween = tweenService:Create(killBlockToMove, Info, Goals)
KillPartTween:Play()
end)
I don’t exactly understand what’s the problem. Could you reexplain it? If your problem is that you want to delay the tween play then use task.wait(), if the problem is that you want the tween to take longer, then, in the tween info, make the first argument a bigger number. If this is not your problem, then explain it clearly, so that I can understand.
EDIT: Maybe your problem is that you want to run the function every 3 seconds? Here’s how you would do it:
while task.wait(3) do
game.ReplicatedStorage:WaitForChild("MoveBlocks"):SetAttribute("Value", --[[The desired value]])
end
Or is it you want the wait time to be longer when the function runs?
local waitTime = 3
--the part making the tween and playing it
waitTime += --the desired value to add
How are you using the Value attribute in MoveBlocks?
Currently every time the property changes it will run the function, so if this is a bool, whether you set it to true or false it will run again.
You should check the value the attribute has changed to then it should be safe to run a loop.
game.......:Connect(function ()
If Value == true then
repeat
--Your code
task.wait(3)
until Value == false
end)
(You’ll need to get the value, I can’t remember offhand whether this is passed as an argument via the connection or not)