local code = game.Workspace.Script
local basep = game.Workspace.Baseplate
local sp = true
while sp == true do
basep.Size = Vector3.new(basep.Size.X - 2,basep.Size.Y,basep.Size.Z - 2)
wait(0.5)
print(basep.Size)
end
if basep.Size == Vector3.new(10, 5, 10) then
print("worked")
end
最后一部分不起作用,我不知道如何在达到X-10 Y-5 Y-10大小时将其停下来(我把print(“ worked”)放进去,所以我可以看看是否它正在工作)
您会将if块放入无限循环内,如下所示:
while sp == true do
basep.Size = Vector3.new(basep.Size.X - 2,basep.Size.Y,basep.Size.Z - 2)
print(basep.Size)
if basep.Size == Vector3.new(10, 5, 10) then
print("worked")
break -- <=== add this if you want to break out of the loop
end
wait(0.5)
end
或者,您可以使用Tween处理动画,然后在动画结束时附加回调。
local TweenService = game:GetService("TweenService")
-- choose an Instance to change
local basep = game.Workspace.Baseplate
-- create a list of properties to change during the animation
local goal = {
Size = Vector3.new(10, 5, 10)
}
-- configure how the animation will work
local timeToComplete = 5 --seconds
local timeToDelay = 0 -- seconds
local tweenInfo = TweenInfo.new(timeToComplete, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, timeToDelay)
-- create the animation and attach a listener for when the animation finishes
local tween = TweenService:Create(basep, tweenInfo, goal)
tween.Completed:Connect(function()
print("worked")
end)
tween:Play()