Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make it so that a tween plays upon found in workspace?

Asked by 3 years ago
local Clickd = script.Parent.ClickDetector
local Button = script.Parent
local RS = game:GetService("ReplicatedStorage")
local EndFolder = RS:WaitForChild("End")
local Pillar = EndFolder.Pillar
local Radius = 250
local Baseplate = game.Workspace.Baseplate
local X  -- nil value
local Y = 0
local Z  -- nil value


Clickd.MouseClick:Connect(function()
    print("Worked!")
    local ClonedPillar = Pillar:Clone()
    ClonedPillar.Parent = workspace
    ClonedPillar.Position = Vector3.new(X,52.171,Z)
    Baseplate.BrickColor = BrickColor.new("Brick yellow")
    Baseplate.Material = Enum.Material.Slate
end)

while true do
    wait()
    X = math.random(-250,Radius)    
    Z = math.random(-250,Radius)    
end

local TweenService = game:GetService("TweenService")
local TweeningInfo = TweenInfo.new(

    5, -- Length        
    Enum.EasingStyle.Quad, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    0, -- Repeat count
    false, -- Repeatable
    1.5 -- Delay

)

local PartProperties = {
    Position = Vector3.new(0,250,0)}
local Tween = TweenService:Create(Pillar,TweeningInfo,PartProperties)


for i, v in pairs(game.Workspace:GetChildren()) do
    if v.Name == "Pillar" then
        Tween:Play()
    end
end



When the cloned Pillar appears in workspace, why does it not slowly levitate? It just appears on the baseplate and the tween does not play

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You could wrap the tween in a function and play it whenever a pillar is added to the workspace.

workspace.ChildAdded:Connect(function(child) if child.Name == "Pillar" then local TweenService = game:GetService("TweenService") local TweeningInfo = TweenInfo.new(

        5, -- Length        
        Enum.EasingStyle.Quad, -- EasingStyle
        Enum.EasingDirection.Out, -- EasingDirection
        0, -- Repeat count
        false, -- Repeatable
        1.5 -- Delay

    )

    local PartProperties = {
        Position = Vector3.new(0,250,0)}
    local Tween = TweenService:Create(child,TweeningInfo,PartProperties)
    Tween:Play()
end

end

0
It did not work, no errors :C RandyN56 23 — 3y
0
I forgot to play the Tween lol, should work now LeedleLeeRocket 1257 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Hello again, I guess it's not solved so I'll help you out. The script isn't working because 1. the loop doesn't allow it to pass through the tween and 2. the tween will play to the original part, not cloned part. Fixing those problems isn't that hard. Here's an example how to result those problems.

local Clickd = script.Parent.ClickDetector
local Button = script.Parent
local RS = game:GetService("ReplicatedStorage")
local EndFolder = RS:WaitForChild("End")
local Pillar = EndFolder.Pillar
local Radius = 250
local Baseplate = game.Workspace.Baseplate
local X  -- nil value
local Y = 0
local Z  -- nil value

local TweenService = game:GetService("TweenService")
local TweeningInfo = TweenInfo.new(

    5, -- Length        
    Enum.EasingStyle.Quad, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    0, -- Repeat count
    false, -- Repeatable
    1.5 -- Delay

)

local PartProperties = {
    Position = Vector3.new(0,250,0)
}

local ClonedPillar -- Nil value.

Clickd.MouseClick:Connect(function()
    X = math.random(-250,Radius) -- Giving "X" a value.
    Z = math.random(-250,Radius) -- Same as X.

    ClonedPillar = Pillar:Clone() -- ClonedPillar will have a variable.
    ClonedPillar.Parent = workspace
    ClonedPillar.Position = Vector3.new(X,52.171,Z)
    Baseplate.BrickColor = BrickColor.new("Brick yellow")
    Baseplate.Material = Enum.Material.Slate

    local Tween = TweenService:Create(ClonedPillar,TweeningInfo,PartProperties) -- Put tween in MouseClick event.

    for i, v in pairs(game.Workspace:GetChildren()) do -- Same with the "for in pairs() do" loop.
        if v.Name == "Pillar" then
            Tween:Play()
        end
    end
end)

Hopefully you understand it and have fun with this script!

Answer this question