Hi, I would like to make a construct that represents stats with 3 parts.
Each of these parts has a script that every 3 seconds should change the Y axis of these parts to a random number.
Script:
local Part = script.Parent
while true do
wait(3)
local num = math.random(2,16)
Part.Size = Vector3.new(1.596, num, 4.54)
end
The script works but
Start Game Status:
After Script Execution Status:
Basically i wanted to Resize those parts from the top.
Thanks
u can change the part position on certain axis according to the size axis. for e.g if u increased the size vertically +1 then u need to add .5 on the y-axis position. In your case
while true do
wait(3)
local num = math.random(2,16)
Part.Size = Vector3.new(1.596, num, 4.54)
Part.Positon = Vector3.new(0, num/2,0)
end
local localPart = script.Parent
function changePartSizeBy(part, sizeChange, pos)
if pos then
part.Size += sizeChange
part.Position += part.CFrame:VectorToWorldSpace(sizeChange / 2)
else
part.Size += sizeChange
part.Position -= part.CFrame:VectorToWorldSpace(sizeChange / 2)
end
end
wait(5)
print("Working...")
local heightIncrease = 5 -- However high you want it to increase by
changePartSizeBy(localPart, Vector3.new(0, heightIncrease, 0), true)
--Where localPart is the part you want to increase the height of
It works but i wanted the part to change size by a math.random from 1 to 16.
As an example: the math.random outputs 5, The part Y size should change to 5 but the part should be attached to the floor in the same time
local function resizeUpward(part: BasePart, size: number)
if typeof(part) ~= "Instance" or not part:IsA("BasePart") then
error("Invalid first argument!")
end
if type(size) ~= "number" then
error("Invalid second argument!")
end
local rootPoint: Vector3 = part.Position - Vector3.new(0, part.Size.Y/2, 0)
part.Size = Vector3.new(part.Size.X, size, part.Size.Z)
part.Position = rootPoint + Vector3.new(0, size/2, 0)
end
while task.wait(1) do
resizeUpward(PART_HERE, math.random(1, 16))
end
Okay, in that case just make heightIncrease equal to math.random(16). No matter what number you put in the function, it will make it increase up by that number relative to its current position. Hope that helped.
--!strict
local ts = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.7, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut)
local function resizeUpwardTweened(part: BasePart, size: number)
if typeof(part) ~= "Instance" or not part:IsA("BasePart") then
error("Invalid first argument!")
end
if type(size) ~= "number" then
error("Invalid second argument!")
end
local rootPoint: Vector3 = part.Position - Vector3.new(0, part.Size.Y/2, 0)
local tweenData = {
Size = Vector3.new(part.Size.X, size, part.Size.Z),
Position = rootPoint + Vector3.new(0, size/2, 0)
}
ts:Create(part, tweenInfo, tweenData):Play()
end
while task.wait(1) do
resizeUpwardTweened(PART_HERE, math.random(1, 16))
end