【问题标题】:Move Roblox Group with Script使用脚本移动 Roblox 组
【发布时间】:2022-09-25 23:59:44
【问题描述】:

我正在尝试克隆一个组并将其位置设置为一个固定的位置。我只能用 .Position 移动组中的特定部分,但我需要整个组移动。有没有简单的方法可以做到这一点?我在 ServerScriptStorage 中的常规脚本中执行此操作,这似乎很好。这是我的代码: 本地 localCharacters = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(Player)
    local HRP = Player.CharacterAdded:Wait()

    local ClonedPart = game.ReplicatedStorage.BaseParts:Clone() -- Gives nil when not set to BaseParts.Part
    ClonedPart.Parent = workspace
    ClonedPart.Position = Vector3.new(0, 15, 0)
end)

    标签: lua roblox


    【解决方案1】:

    您可以根据自己的喜好使用SetPrimaryPartCFramePivotTo。我之前推荐过SetPrimaryPartCFrame,但它被弃用了。 PivotTo 主要是向后兼容的替代品,因此现在应该使用它。您的模型应该有一个具有 PrimaryPart 属性的主要零件集。我还假设 BaseParts 是一个模型,并且当您设置 Position 属性时您的代码错误。

    game.Players.PlayerAdded:Connect(function(Player)
        local HRP = Player.CharacterAdded:Wait()
    
        local ClonedPart = game.ReplicatedStorage.BaseParts:Clone()
    
        ClonedPart:PivotTo(CFrame.new(Vector3.new(0, 15, 0))) --Always set other properties before the parent
        ClonedPart.Parent = workspace
    end)
    

    【讨论】:

    • 只是想说SetPrimaryPartCFrame 在一个月前被弃用了。它应该在调用 PivotTo 而不是 SetPrimaryPartCFrame 而没有任何其他更改时工作。
    猜你喜欢
    • 2018-12-28
    • 2014-02-11
    • 2019-10-15
    • 2020-12-10
    • 2018-06-17
    • 2023-02-02
    • 2020-07-02
    • 2018-11-27
    • 2015-02-12
    相关资源
    最近更新 更多