BasePart

Mostrar obsoleto

*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.

No creable
No explorable

Resumen

Propiedades

Propiedades heredados de PVInstance

Métodos

Métodos heredados de PVInstance

Propiedades

Anchored

Leer paralelo

Muestras de código

Part Anchored Toggle

local part = script.Parent
-- Create a ClickDetector so we can tell when the part is clicked
local cd = Instance.new("ClickDetector", part)
-- This function updates how the part looks based on its Anchored state
local function updateVisuals()
if part.Anchored then
-- When the part is anchored...
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.DiamondPlate
else
-- When the part is unanchored...
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Wood
end
end
local function onToggle()
-- Toggle the anchored property
part.Anchored = not part.Anchored
-- Update visual state of the brick
updateVisuals()
end
-- Update, then start listening for clicks
updateVisuals()
cd.MouseClick:Connect(onToggle)

AssemblyAngularVelocity

No replicado
Leer paralelo

AssemblyCenterOfMass

Solo lectura
No replicado
Leer paralelo

AssemblyLinearVelocity

No replicado
Leer paralelo

AssemblyMass

Solo lectura
No replicado
Leer paralelo

AssemblyRootPart

Solo lectura
No replicado
Leer paralelo

AudioCanCollide

Leer paralelo

BackSurface

Leer paralelo

BottomSurface

Leer paralelo

BrickColor

No replicado
Leer paralelo

CFrame

Leer paralelo

Muestras de código

Configurando el marco CFrame de parte

local part = script.Parent:WaitForChild("Part")
local otherPart = script.Parent:WaitForChild("OtherPart")
-- Restablecer el marco de la parte en (0, 0, 0) sin rotación.
-- Esto a veces se llama la "identidad" CFrame
part.CFrame = CFrame.new()
-- Establecer en una posición específica (X, Y, Z)
part.CFrame = CFrame.new(0, 25, 10)
-- Igual que lo anterior, pero utilice un Vector3 en su lugar
local point = Vector3.new(0, 25, 10)
part.CFrame = CFrame.new(point)
-- Establece el marco de la parte en un punto, mirando a otro
local lookAtPoint = Vector3.new(0, 20, 15)
part.CFrame = CFrame.lookAt(point, lookAtPoint)
-- Girar el marco de la parte por pi/2 radianes en el eje X local
part.CFrame = part.CFrame * CFrame.Angles(math.pi / 2, 0, 0)
-- Gira el marco de la parte en 45 grados en el eje Y local
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(45), 0)
-- Gira el marco de la parte en 180 grados en el eje global Z (nota la orden!)
part.CFrame = CFrame.Angles(0, 0, math.pi) * part.CFrame -- Pi radianos es igual a 180 grados
-- Componer dos marcos C se hace usando * (el operador de multiplicación)
part.CFrame = CFrame.new(2, 3, 4) * CFrame.new(4, 5, 6) --> igual a CFrame.new(6, 8, 10)
-- A diferencia de la multiplicación algebraica, la composición de CFrame NO es comunicativa: ¡a * b no es necesariamente b * a!
-- Imagina * como una serie ORDENADA de acciones. Por ejemplo, las siguientes líneas producen diferentes CFrames:
-- 1) Desliza las unidades de parte 5 en X.
-- 2) Gira la pieza 45 grados alrededor de su eje Y.
part.CFrame = CFrame.new(5, 0, 0) * CFrame.Angles(0, math.rad(45), 0)
-- 1) Gira la pieza 45 grados alrededor de su eje Y.
-- 2) Desliza las unidades de parte 5 en X.
part.CFrame = CFrame.Angles(0, math.rad(45), 0) * CFrame.new(5, 0, 0)
-- No hay una "división de CFrame", sino que simplemente "hacer la operación inversa".
part.CFrame = CFrame.new(4, 5, 6) * CFrame.new(4, 5, 6):Inverse() --> es igual a CFrame.new(0, 0, 0)
part.CFrame = CFrame.Angles(0, 0, math.pi) * CFrame.Angles(0, 0, math.pi):Inverse() --> igual a CFrame.Angles(0, 0, 0)
-- Posiciona una parte en relación con otra (en este caso, pon nuestra parte encima de otra parte)
part.CFrame = otherPart.CFrame * CFrame.new(0, part.Size.Y / 2 + otherPart.Size.Y / 2, 0)

CanCollide

Leer paralelo

Muestras de código

Fade Door

-- Paste into a Script inside a tall part
local part = script.Parent
local OPEN_TIME = 1
-- Can the door be opened at the moment?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("Black")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("Bright blue")
end
local function onTouch(otherPart)
-- If the door was already open, do nothing
if debounce then
print("D")
return
end
-- Check if touched by a Humanoid
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("not human")
return
end
-- Perform the door opening sequence
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()

CanQuery

Leer paralelo

CanTouch

Leer paralelo

CastShadow

Leer paralelo

CenterOfMass

Solo lectura
No replicado
Leer paralelo

CollisionGroup

No replicado
Leer paralelo

Muestras de código

PhysicsService:RegisterCollisionGroup

local PhysicsService = game:GetService("PhysicsService")
local collisionGroupBall = "CollisionGroupBall"
local collisionGroupDoor = "CollisionGroupDoor"
-- Register collision groups
PhysicsService:RegisterCollisionGroup(collisionGroupBall)
PhysicsService:RegisterCollisionGroup(collisionGroupDoor)
-- Assign parts to collision groups
script.Parent.BallPart.CollisionGroup = collisionGroupBall
script.Parent.DoorPart.CollisionGroup = collisionGroupDoor
-- Set groups as non-collidable with each other and check the result
PhysicsService:CollisionGroupSetCollidable(collisionGroupBall, collisionGroupDoor, false)
print(PhysicsService:CollisionGroupsAreCollidable(collisionGroupBall, collisionGroupDoor)) --> false

Color

No replicado
Leer paralelo

Muestras de código

Character Health Body Color

-- Paste into a Script within StarterCharacterScripts
-- Then play the game, and fiddle with your character's health
local char = script.Parent
local human = char.Humanoid
local colorHealthy = Color3.new(0.4, 1, 0.2)
local colorUnhealthy = Color3.new(1, 0.4, 0.2)
local function setColor(color)
for _, child in pairs(char:GetChildren()) do
if child:IsA("BasePart") then
child.Color = color
while child:FindFirstChildOfClass("Decal") do
child:FindFirstChildOfClass("Decal"):Destroy()
end
elseif child:IsA("Accessory") then
child.Handle.Color = color
local mesh = child.Handle:FindFirstChildOfClass("SpecialMesh")
if mesh then
mesh.TextureId = ""
end
elseif child:IsA("Shirt") or child:IsA("Pants") then
child:Destroy()
end
end
end
local function update()
local percentage = human.Health / human.MaxHealth
-- Create a color by tweening based on the percentage of your health
-- The color goes from colorHealthy (100%) ----- > colorUnhealthy (0%)
local color = Color3.new(
colorHealthy.R * percentage + colorUnhealthy.r * (1 - percentage),
colorHealthy.G * percentage + colorUnhealthy.g * (1 - percentage),
colorHealthy.B * percentage + colorUnhealthy.b * (1 - percentage)
)
setColor(color)
end
update()
human.HealthChanged:Connect(update)

CurrentPhysicalProperties

Solo lectura
No replicado
Leer paralelo

CustomPhysicalProperties

Leer paralelo

Muestras de código

Set CustomPhysicalProperties

local part = script.Parent
-- This will make the part light and bouncy!
local DENSITY = 0.3
local FRICTION = 0.1
local ELASTICITY = 1
local FRICTION_WEIGHT = 1
local ELASTICITY_WEIGHT = 1
local physProperties = PhysicalProperties.new(DENSITY, FRICTION, ELASTICITY, FRICTION_WEIGHT, ELASTICITY_WEIGHT)
part.CustomPhysicalProperties = physProperties

EnableFluidForces

Leer paralelo

ExtentsCFrame

Solo lectura
No replicado
Leer paralelo

ExtentsSize

Solo lectura
No replicado
Leer paralelo

FrontSurface

Leer paralelo

LeftSurface

Leer paralelo

LocalTransparencyModifier

Oculto
No replicado
Leer paralelo

Locked

Leer paralelo

Muestras de código

Recursive Unlock

-- Paste into a Script within a Model you want to unlock
local model = script.Parent
-- This function recurses through a model's heirarchy and unlocks
-- every part that it encounters.
local function recursiveUnlock(object)
if object:IsA("BasePart") then
object.Locked = false
end
-- Call the same function on the children of the object
-- The recursive process stops if an object has no children
for _, child in pairs(object:GetChildren()) do
recursiveUnlock(child)
end
end
recursiveUnlock(model)

Mass

Solo lectura
No replicado
Leer paralelo

Massless

Leer paralelo
Leer paralelo

MaterialVariant

No replicado
Leer paralelo

Orientation

Oculto
No replicado
Leer paralelo

Muestras de código

Spinner de parte

local part = script.Parent
local INCREMENT = 360 / 20
-- Girar la pieza continuamente
while true do
for degrees = 0, 360, INCREMENT do
-- Establecer solo la rotación del eje Y
part.Rotation = Vector3.new(0, degrees, 0)
-- Una mejor manera de hacer esto sería establecer CFrame
--part.CFrame = CFrame. nuevo (part.Position) * CFrame.Angles(0, math.rad(grados), 0)
task.wait()
end
end

PivotOffset

Leer paralelo

Muestras de código

Reset Pivot

local function resetPivot(model)
local boundsCFrame = model:GetBoundingBox()
if model.PrimaryPart then
model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame)
else
model.WorldPivot = boundsCFrame
end
end
resetPivot(script.Parent)
Reloj de manos

local function createHand(length, width, yOffset)
local part = Instance.new("Part")
part.Size = Vector3.new(width, 0.1, length)
part.Material = Enum.Material.Neon
part.PivotOffset = CFrame.new(0, -(yOffset + 0.1), length / 2)
part.Anchored = true
part.Parent = workspace
return part
end
local function positionHand(hand, fraction)
hand:PivotTo(CFrame.fromEulerAnglesXYZ(0, -fraction * 2 * math.pi, 0))
end
-- Crear dial
for i = 0, 11 do
local dialPart = Instance.new("Part")
dialPart.Size = Vector3.new(0.2, 0.2, 1)
dialPart.TopSurface = Enum.SurfaceType.Smooth
if i == 0 then
dialPart.Size = Vector3.new(0.2, 0.2, 2)
dialPart.Color = Color3.new(1, 0, 0)
end
dialPart.PivotOffset = CFrame.new(0, -0.1, 10.5)
dialPart.Anchored = true
dialPart:PivotTo(CFrame.fromEulerAnglesXYZ(0, (i / 12) * 2 * math.pi, 0))
dialPart.Parent = workspace
end
-- Crear manos
local hourHand = createHand(7, 1, 0)
local minuteHand = createHand(10, 0.6, 0.1)
local secondHand = createHand(11, 0.2, 0.2)
-- Reloj de ejecución
while true do
local components = os.date("*t")
positionHand(hourHand, (components.hour + components.min / 60) / 12)
positionHand(minuteHand, (components.min + components.sec / 60) / 60)
positionHand(secondHand, components.sec / 60)
task.wait()
end

Position

Oculto
No replicado
Leer paralelo

ReceiveAge

Oculto
Solo lectura
No replicado
Leer paralelo

Reflectance

Leer paralelo

ResizeIncrement

Solo lectura
No replicado
Leer paralelo

ResizeableFaces

Solo lectura
No replicado
Leer paralelo

Muestras de código

Resize Handles

-- Put this Script in several kinds of BasePart, like
-- Part, TrussPart, WedgePart, CornerWedgePart, etc.
local part = script.Parent
-- Create a handles object for this part
local handles = Instance.new("Handles")
handles.Adornee = part
handles.Parent = part
-- Manually specify the faces applicable for this handle
handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left)
-- Alternatively, use the faces on which the part can be resized.
-- If part is a TrussPart with only two Size dimensions
-- of length 2, then ResizeableFaces will only have two
-- enabled faces. For other parts, all faces will be enabled.
handles.Faces = part.ResizeableFaces

RightSurface

Leer paralelo

RootPriority

Leer paralelo

Rotation

No replicado
Leer paralelo
No replicado
Leer paralelo

Muestras de código

Pyramid Builder

local TOWER_BASE_SIZE = 30
local position = Vector3.new(50, 50, 50)
local hue = math.random()
local color0 = Color3.fromHSV(hue, 1, 1)
local color1 = Color3.fromHSV((hue + 0.35) % 1, 1, 1)
local model = Instance.new("Model")
model.Name = "Tower"
for i = TOWER_BASE_SIZE, 1, -2 do
local part = Instance.new("Part")
part.Size = Vector3.new(i, 2, i)
part.Position = position
part.Anchored = true
part.Parent = model
-- Tween from color0 and color1
local perc = i / TOWER_BASE_SIZE
part.Color = Color3.new(
color0.R * perc + color1.R * (1 - perc),
color0.G * perc + color1.G * (1 - perc),
color0.B * perc + color1.B * (1 - perc)
)
position = position + Vector3.new(0, part.Size.Y, 0)
end
model.Parent = workspace
Leer paralelo

Transparency

Leer paralelo

Muestras de código

Fade Door

-- Paste into a Script inside a tall part
local part = script.Parent
local OPEN_TIME = 1
-- Can the door be opened at the moment?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("Black")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("Bright blue")
end
local function onTouch(otherPart)
-- If the door was already open, do nothing
if debounce then
print("D")
return
end
-- Check if touched by a Humanoid
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("not human")
return
end
-- Perform the door opening sequence
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()

Métodos

AngularAccelerationToTorque

Parámetros

angAcceleration: Vector3
Valor predeterminado: ""
angVelocity: Vector3
Valor predeterminado: "0, 0, 0"

Devuelve

ApplyAngularImpulse

()

Parámetros

impulse: Vector3
Valor predeterminado: ""

Devuelve

()

ApplyImpulse

()

Parámetros

impulse: Vector3
Valor predeterminado: ""

Devuelve

()

ApplyImpulseAtPosition

()

Parámetros

impulse: Vector3
Valor predeterminado: ""
position: Vector3
Valor predeterminado: ""

Devuelve

()

CanCollideWith

Escribir paralelo

Parámetros

part: BasePart
Valor predeterminado: ""

Devuelve

CanSetNetworkOwnership


Devuelve

Muestras de código

Compruebe si se puede establecer la propiedad de red de una parte

local part = workspace:FindFirstChild("Part")
if part and part:IsA("BasePart") then
local canSet, errorReason = part:CanSetNetworkOwnership()
if canSet then
print(part:GetFullName() .. "'s Network Ownership can be changed!")
else
warn("Cannot change the Network Ownership of " .. part:GetFullName() .. " because: " .. errorReason)
end
end

GetClosestPointOnSurface

Parámetros

position: Vector3
Valor predeterminado: ""

Devuelve

GetConnectedParts

Instances
Escribir paralelo

Parámetros

recursive: boolean
Valor predeterminado: false

Devuelve

Instances

GetJoints

Instances
Escribir paralelo

Devuelve

Instances

GetMass

Escribir paralelo

Devuelve

Muestras de código

Encontrar la masa de una parte

local myPart = Instance.new("Part")
myPart.Size = Vector3.new(4, 6, 4)
myPart.Anchored = true
myPart.Parent = workspace
local myMass = myPart:GetMass()
print("My part's mass is " .. myMass)

GetNetworkOwner

Escribir paralelo

Devuelve

GetNetworkOwnershipAuto

Escribir paralelo

Devuelve

GetNoCollisionConstraints

Instances

Devuelve

Instances

GetRootPart

Escribir paralelo

Devuelve

GetTouchingParts

Instances

Devuelve

Instances

GetVelocityAtPosition

Escribir paralelo

Parámetros

position: Vector3
Valor predeterminado: ""

Devuelve

IsGrounded

Escribir paralelo

Devuelve

Resize

Parámetros

normalId: Enum.NormalId
Valor predeterminado: ""
deltaAmount: number
Valor predeterminado: ""

Devuelve

SetNetworkOwner

()

Parámetros

playerInstance: Player
Valor predeterminado: "nil"

Devuelve

()

SetNetworkOwnershipAuto

()

Devuelve

()

TorqueToAngularAcceleration

Parámetros

torque: Vector3
Valor predeterminado: ""
angVelocity: Vector3
Valor predeterminado: "0, 0, 0"

Devuelve

IntersectAsync

Proporciona

Parámetros

parts: Instances
Valor predeterminado: ""
collisionfidelity: Enum.CollisionFidelity
Valor predeterminado: "Default"
renderFidelity: Enum.RenderFidelity
Valor predeterminado: "Automatic"

Devuelve

SubtractAsync

Proporciona

Parámetros

parts: Instances
Valor predeterminado: ""
collisionfidelity: Enum.CollisionFidelity
Valor predeterminado: "Default"
renderFidelity: Enum.RenderFidelity
Valor predeterminado: "Automatic"

Devuelve

Muestras de código

BasePart:SubtracciónAsync()

local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- Realizar operación de resta
local success, newSubtract = pcall(function()
return mainPart:SubtractAsync(otherParts)
end)
-- Si la operación tiene éxito, posiciónela en la misma ubicación y asignársela al espacio de trabajo
if success and newSubtract then
newSubtract.Position = mainPart.Position
newSubtract.Parent = Workspace
end
-- Destruir piezas originales que se mantienen intactas después de la operación
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end

UnionAsync

Proporciona

Parámetros

parts: Instances
Valor predeterminado: ""
collisionfidelity: Enum.CollisionFidelity
Valor predeterminado: "Default"
renderFidelity: Enum.RenderFidelity
Valor predeterminado: "Automatic"

Devuelve

Muestras de código

BasePart:UnionAsync()

local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- Perform union operation
local success, newUnion = pcall(function()
return mainPart:UnionAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newUnion then
newUnion.Position = mainPart.Position
newUnion.Parent = Workspace
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end

Eventos

TouchEnded

Parámetros

otherPart: BasePart

Muestras de código

Touching Parts Count

local part = script.Parent
local billboardGui = Instance.new("BillboardGui")
billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.Adornee = part
billboardGui.AlwaysOnTop = true
billboardGui.Parent = part
local tl = Instance.new("TextLabel")
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
tl.Parent = billboardGui
local numTouchingParts = 0
local function onTouch(otherPart)
print("Touch started: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("Touch ended: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

Touched

Parámetros

otherPart: BasePart

Muestras de código

Touching Parts Count

local part = script.Parent
local billboardGui = Instance.new("BillboardGui")
billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.Adornee = part
billboardGui.AlwaysOnTop = true
billboardGui.Parent = part
local tl = Instance.new("TextLabel")
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
tl.Parent = billboardGui
local numTouchingParts = 0
local function onTouch(otherPart)
print("Touch started: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("Touch ended: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
Model Touched

local model = script.Parent
local function onTouched(otherPart)
-- Ignore instances of the model coming in contact with itself
if otherPart:IsDescendantOf(model) then
return
end
print(model.Name .. " collided with " .. otherPart.Name)
end
for _, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
child.Touched:Connect(onTouched)
end
end