How would I call this function everytime I want a new part created?
I want to call the function then change the parts color and then size
I am planning on having multiple parts so I figured a function would make my code way cleaner than copy and pasting the same attributes for every part 10 times.
local tweenService = game:GetService("TweenService")
local tweenInformation = TweenInfo.new(
5,
Enum.EasingStyle.Quint,
Enum.EasingDirection.InOut,
0,
false,
0
)
function createPart(color)
local Part = Instance.new("Part")
color = Part.BrickColor
Part.Size = Vector3.new(1,1,1)
Part.Anchored = true
Part.CanCollide = false
Part.Material = Enum.Material.SmoothPlastic
Part.Parent = game.Workspace
end
local partInfo1 ={
Size = Vector3.new(2.5,0.3,2.5);
}
local partInfo2 = {
Size = Vector3.new(2.7,0.2,2.7);
}
local tween1 = tweenService:Create(createPart,tweenInformation,partInfo1)
local tween2 = tweenService:Create(createPart,tweenInformation,partInfo2)
wait(10)
tween1:Play()
tween2:Play()
Do you mean this as in when any new part in workspace is created this should fire?
or
Do you want to make something that will call this entire script when you want it to at runtime?
local tweenService = game:GetService("TweenService")
local tweenInformation = TweenInfo.new(
5,
Enum.EasingStyle.Quint,
Enum.EasingDirection.InOut,
0,
false,
0
)
function createPart(color)
local Part = Instance.new("Part")
Part.BrickColor = color
Part.Size = Vector3.new(1,1,1)
Part.Anchored = true
Part.CanCollide = false
Part.Material = Enum.Material.SmoothPlastic
Part.Parent = game.Workspace
return Part
end
local partInfo1 ={
Size = Vector3.new(2.5,0.3,2.5);
}
local partInfo2 = {
Size = Vector3.new(2.7,0.2,2.7);
}
local function makeNewPartAndAnimate()
local newPart = createPart()
local tween1 = tweenService:Create(newPart, tweenInformation, partInfo1)
local tween2 = tweenService:Create(newPart, tweenInformation, partInfo2)
wait(10)
tween1:Play()
tween2:Play()
end
-- Call makeNewPartAndAnimate() when you want a new part to be added