如何使工作区中的零件可见并开始移动



我尝试使用的按钮位于StarterGUI中。不知道这是否有帮助。对于脚本编写来说,我还是个新手,但是看到了另一篇类似的文章并使用了该代码。这是我在LocalScript:中的代码

local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
local productID = 1218445531

script.Parent.MouseButton1Click:Connect(function()

PurchaseEvent:FireServer(productID)
end)
if MarketplaceService:PlayerOwnsAsset(1218445531) then
--Here is where the thing is supposed to happen
end

首先,您需要获得对零件的引用,一种方法是使用类似local part = workspace:WaitForChild("PartName")的东西

为了使其可见,需要将透明度设置为0。如果你不想让玩家走过这个部分,你可能还需要打开与CanColide的碰撞。还建议固定零件以防止其掉落。

part.Transparency = 0; -- makes it visible
part.CanColide = true; -- makes sure other objects cant go through this
part.Anchored = true; -- prevents the object from falling

有很多方法可以使零件移动。如果零件应该从一个地方到另一个地方,并且只有一个目的地,那么推文可能会很有用(请参阅推文服务(。

另一种方法是使用心跳循环来改变每帧的位置(请参阅RunService.Heartbeat(

local keepMoving = true; -- change this to false to stop moving
local RunService = game:GetService("RunService");
local direction = Vector3.new(0, 1, 0); -- change this to anything you want
while (keepMoving) do
local timePassed = RunService.Heartbeat:Wait(); -- wait one frame, roughly 0.016 of a second.
part.Position += direction * timePassed; -- move the part in the direction 
end

这将使part每秒向上移动1个螺柱。

最新更新