Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

0

It did not work, no errors :C

0

I forgot to play the Tween lol, should work now

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.