Clase de motor
Humanoid
*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.
Resumen
Propiedades
Métodos
Eventos
Muestras de código
Efecto de Lente de Bobble al Caminar
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- ¿Está caminando el personaje?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- Reduce el CameraOffset para que vuelva a su posición regular.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)Referencia API
Propiedades
AutoJumpEnabled
Muestras de código
Alternar Auto-Salto
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- Actualizar el texto del botón
if player.AutoJumpEnabled then
button.Text = "El Auto-Salto está ACTIVADO"
else
button.Text = "El Auto-Salto está DESACTIVADO"
end
-- Reflejar la propiedad en el personaje del jugador, si tiene uno
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- Alternar el auto-salto
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- Actualizar todo lo demás
update()
end
button.Activated:Connect(onActivated)
update()AutoRotate
Muestras de código
Botón de AutoRotación
local button = script.Parent
local enabled = true
local ON_COLOR = BrickColor.Green()
local OFF_COLOR = BrickColor.Red()
local function touchButton(humanoid)
if enabled then
enabled = false
button.BrickColor = OFF_COLOR
if humanoid.AutoRotate then
print(humanoid:GetFullName() .. " ya no puede auto-rotar!")
humanoid.AutoRotate = false
else
print(humanoid:GetFullName() .. " ahora puede auto-rotar!")
humanoid.AutoRotate = true
end
task.wait(1)
button.BrickColor = ON_COLOR
enabled = true
end
end
local function onTouched(hit)
local char = hit:FindFirstAncestorWhichIsA("Model")
if char then
local humanoid = char:FindFirstChildOfClass("Humanoid")
if humanoid then
touchButton(humanoid)
end
end
end
button.Touched:Connect(onTouched)
button.BrickColor = ON_COLORCameraOffset
Muestras de código
Efecto de Lente de Bobble al Caminar
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- ¿Está caminando el personaje?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- Reduce el CameraOffset para que vuelva a su posición regular.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)CollisionType
DisplayDistanceType
Muestras de código
Mostrando la Salud y Nombre de un Humanoide
local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100LeftLeg
maxHealth
MaxSlopeAngle
Muestras de código
Limitando la Pendiente que un Humanoide Puede Subir
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char:FindFirstChild("Humanoid")
h.MaxSlopeAngle = 30MoveDirection
Muestras de código
Efecto de Lente de Bobble al Caminar
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- ¿Está caminando el personaje?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
else
-- Reduce el CameraOffset para que vuelva a su posición regular.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)NameOcclusion
Muestras de código
Ocultar Nombres de Jugadores
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.NamOcclusion = Enum.NameOcclusion.OccludeAll
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)RightLeg
Torso
Métodos
AddAccessory
Parámetros
Devuelve
()
Muestras de código
[Humanoid] Ejemplo de AddAccessory
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local clockworksShades = Instance.new("Accessory")
clockworksShades.Name = "ClockworksShades"
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1, 1.6, 1)
handle.Parent = clockworksShades
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0, -0.24, -0.45)
faceFrontAttachment.Parent = handle
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1, 1.3, 1)
mesh.MeshId = "rbxassetid://1577360"
mesh.TextureId = "rbxassetid://1577349"
mesh.Parent = handle
humanoid:AddAccessory(clockworksShades)AddCustomStatus
AddStatus
ApplyDescription
ApplyDescriptionAsync
Humanoid:ApplyDescriptionAsync(
):()
Parámetros
| Valor predeterminado: "Default" |
Devuelve
()
ApplyDescriptionReset
ApplyDescriptionResetAsync
Humanoid:ApplyDescriptionResetAsync(
):()
Parámetros
| Valor predeterminado: "Default" |
Devuelve
()
BuildRigFromAttachments
Humanoid:BuildRigFromAttachments():()
Devuelve
()
Muestras de código
Puerto Lua de BuildRigFromAttachments
local function createJoint(jointName, att0, att1)
local partForJoint = att1.Parent
while partForJoint and not partForJoint:IsA("BasePart") do
partForJoint = partForJoint.Parent
end
local oldJoint = partForJoint:FindFirstChild(jointName)
if oldJoint and oldJoint:IsA("AnimationConstraint") then
oldJoint.Attachment0 = att0
oldJoint.Attachment1 = att1
oldJoint.Parent = partForJoint
else
local ac = Instance.new("AnimationConstraint")
ac.Name = jointName
ac.IsKinematic = true
ac.Attachment0 = att0
ac.Attachment1 = att1
ac.Parent = partForJoint
end
end
local function collectRigAttachments(part)
local rigAttachments = {}
for _, child in pairs(part:GetChildren()) do
if child:IsA("Attachment") and child.Name:find("RigAttachment$") then
rigAttachments[child.Name] = child
end
end
-- Los huesos pueden contener RigAttachments más profundos que anulan los del nivel de parte
-- (esqueleto extendido R15+).
for _, child in pairs(part:GetChildren()) do
if child:IsA("Bone") then
for _, descendant in pairs(child:GetDescendants()) do
if descendant:IsA("Attachment") and descendant.Name:find("RigAttachment$") then
rigAttachments[descendant.Name] = descendant
end
end
end
end
return rigAttachments
end
local function buildJointsFromAttachments(part, characterParts, visitedParts)
if not part or visitedParts[part] then
return
end
visitedParts[part] = true
local rigAttachments = collectRigAttachments(part)
for attachmentName, attachment in pairs(rigAttachments) do
local jointName = attachmentName:sub(1, #attachmentName - #"RigAttachment")
if not part:FindFirstChild(jointName) then
for _, characterPart in pairs(characterParts) do
if not visitedParts[characterPart] then
local matchingAttachment = characterPart:FindFirstChild(attachmentName)
if matchingAttachment and matchingAttachment:IsA("Attachment") then
createJoint(jointName, attachment, matchingAttachment)
buildJointsFromAttachments(characterPart, characterParts, visitedParts)
break
end
end
end
end
end
end
local function buildRigFromAttachments(humanoid)
local rootPart = humanoid.RootPart
assert(rootPart, "El Humanoid no tiene HumanoidRootPart.")
local characterParts = {}
for _, descendant in ipairs(humanoid.Parent:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(characterParts, descendant)
end
end
local visitedParts = {}
buildJointsFromAttachments(rootPart, characterParts, visitedParts)
end
local humanoid = script.Parent:WaitForChild("Humanoid")
buildRigFromAttachments(humanoid)Importador de Paquetes R15
local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")
local PACKAGE_ASSET_ID = 193700907 -- Interruptor de circuito
local function addAttachment(part, name, position, orientation)
local attachment = Instance.new("Attachment")
attachment.Name = name
attachment.Parent = part
if position then
attachment.Position = position
end
if orientation then
attachment.Orientation = orientation
end
return attachment
end
local function createBaseCharacter()
local character = Instance.new("Model")
local humanoid = Instance.new("Humanoid")
humanoid.Parent = character
local rootPart = Instance.new("Part")
rootPart.Name = "HumanoidRootPart"
rootPart.Size = Vector3.new(2, 2, 1)
rootPart.Transparency = 1
rootPart.Parent = character
addAttachment(rootPart, "RootRigAttachment")
local head = Instance.new("Part")
head.Name = "Head"
head.Size = Vector3.new(2, 1, 1)
head.Parent = character
local headMesh = Instance.new("SpecialMesh")
headMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
headMesh.MeshType = Enum.MeshType.Head
headMesh.Parent = head
local face = Instance.new("Decal")
face.Name = "face"
face.Texture = "rbxasset://textures/face.png"
face.Parent = head
addAttachment(head, "FaceCenterAttachment")
addAttachment(head, "FaceFrontAttachment", Vector3.new(0, 0, -0.6))
addAttachment(head, "HairAttachment", Vector3.new(0, 0.6, 0))
addAttachment(head, "HatAttachment", Vector3.new(0, 0.6, 0))
addAttachment(head, "NeckRigAttachment", Vector3.new(0, -0.5, 0))
return character, humanoid
end
local function createR15Package(packageAssetId)
local packageAssetInfo = MarketplaceService:GetProductInfoAsync(packageAssetId)
local character, humanoid = createBaseCharacter()
character.Name = packageAssetInfo.Name
local assetIds = AssetService:GetAssetIdsForPackageAsync(packageAssetId)
for _, assetId in pairs(assetIds) do
local limb = InsertService:LoadAsset(assetId)
local r15 = limb:FindFirstChild("R15")
if r15 then
for _, part in pairs(r15:GetChildren()) do
part.Parent = character
end
else
for _, child in pairs(limb:GetChildren()) do
child.Parent = character
end
end
end
humanoid:BuildRigFromAttachments()
return character
end
local r15Package = createR15Package(PACKAGE_ASSET_ID)
r15Package.Parent = workspaceChangeState
Parámetros
| Valor predeterminado: "None" |
Devuelve
()
Muestras de código
Doble Salto
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local doubleJumpEnabled = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not doubleJumpEnabled then
task.wait(0.2)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
doubleJumpEnabled = true
end
end
elseif newState == Enum.HumanoidStateType.Landed then
doubleJumpEnabled = false
end
end)
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.Space then
if doubleJumpEnabled then
if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.spawn(function()
doubleJumpEnabled = false
end)
end
end
end
end)GetAccessories
Devuelve
Muestras de código
Eliminar accesorios después de cargar
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- Todos los accesorios se han cargado en este punto
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destruyendo %d accesorios para %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Asegúrate de desconectar nuestra conexión al jugador después de que se vaya
-- para permitir que el jugador sea recolectado como basura
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)GetAppliedDescription
GetBodyPartR15
Parámetros
Devuelve
GetLimb
Parámetros
Devuelve
Muestras de código
Obteniendo las extremidades de un Humanoid
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
for _, child in pairs(character:GetChildren()) do
local limb = humanoid:GetLimb(child)
if limb ~= Enum.Limb.Unknown then
print(child.Name .. " es parte de la extremidad " .. limb.Name)
end
endGetPlayingAnimationTracks
GetState
Devuelve
Muestras de código
Doble Salto
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local doubleJumpEnabled = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not doubleJumpEnabled then
task.wait(0.2)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
doubleJumpEnabled = true
end
end
elseif newState == Enum.HumanoidStateType.Landed then
doubleJumpEnabled = false
end
end)
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.Space then
if doubleJumpEnabled then
if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.spawn(function()
doubleJumpEnabled = false
end)
end
end
end
end)GetStateEnabled
Parámetros
Devuelve
Muestras de código
Configuración y Obtención de Estados Humanoides
local humanoid = script.Parent:WaitForChild("Humanoid")
-- Establecer estado
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
-- Obtener estado
print(humanoid:GetStateEnabled(Enum.HumanoidStateType.Jumping)) -- falsoGetStatuses
HasCustomStatus
HasStatus
LoadAnimation
loadAnimation
Move
Devuelve
()
Muestras de código
Moviendo un Humanoide Hacia Adelante
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
RunService:BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
if player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid:Move(Vector3.new(0, 0, -1), true)
end
end
end)MoveTo
Devuelve
()
Muestras de código
Movimiento Humanoide Sin Tiempo de Espera
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- escucha cuando el humanoide alcanza su objetivo
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- comienza a caminar
humanoid:MoveTo(targetPoint)
-- ejecuta en un nuevo hilo para no bloquear la función
task.spawn(function()
while not targetReached do
-- ¿existe todavía el humanoide?
if not (humanoid and humanoid.Parent) then
break
end
-- ¿ha cambiado el objetivo?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresca el tiempo de espera
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- desconectar la conexión si aún está conectada
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "¡Destino alcanzado!") or "¡Falló en alcanzar el destino!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)PlayEmote
PlayEmoteAsync
RemoveAccessories
Humanoid:RemoveAccessories():()
Devuelve
()
Muestras de código
Eliminar accesorios después de cargar
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- Todos los accesorios se han cargado en este punto
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destruyendo %d accesorios para %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Asegúrate de desconectar nuestra conexión al jugador después de que se vaya
-- para permitir que el jugador sea recolectado como basura
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)RemoveCustomStatus
RemoveStatus
ReplaceBodyPartR15
Parámetros
Devuelve
SetStateEnabled
Parámetros
Devuelve
()
Muestras de código
Enfriamiento de Salto
local character = script.Parent
local JUMP_DEBOUNCE = 1
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
task.wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)TakeDamage
Parámetros
Devuelve
()
Muestras de código
Dañando a un Humanoide
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid:TakeDamage(99)takeDamage
UnequipTools
Humanoid:UnequipTools():()
Devuelve
()
Eventos
AnimationPlayed
ApplyDescriptionFinished
Parámetros
Climbing
Parámetros
Muestras de código
Humanoide.Subiendo
local Players = game:GetService("Players")
local function onCharacterClimbing(character, speed)
print(character.Name, "está subiendo a una velocidad de", speed, "estudios / segundo.")
end
local function onCharacterAdded(character)
character.Humanoid.Climbing:Connect(function(speed)
onCharacterClimbing(character, speed)
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)CustomStatusAdded
CustomStatusRemoved
Died
Muestras de código
Humanoid.Died
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
print(player.Name, "¡ha muerto!")
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)HealthChanged
Parámetros
Muestras de código
Humanoid.HealthChanged
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local currentHealth = humanoid.Health
local function onHealthChanged(health)
local change = math.abs(currentHealth - health)
print("La salud del humanoide", (currentHealth > health and "disminuyó en" or "aumentó en"), change)
currentHealth = health
end
humanoid.HealthChanged:Connect(onHealthChanged)
end
player.CharacterAdded:Connect(onCharacterAdded)Barras de Salud
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Pega el script en un LocalScript que esté
-- parentado a un Frame dentro de un Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- negro
-- Esta función se llama cuando la salud del humanoide cambia
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Cambia el tamaño de la barra interior
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Cambia el color de la barra de salud
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- rojo
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- amarillo
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- verde
end
end
-- Esta función se llama cuando el jugador aparece
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Patrón: actualizar una vez ahora, luego cada vez que cambie la salud
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Conectar nuestro oyente de aparición; llamarlo si ya ha aparecido
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
endMoveToFinished
Parámetros
Muestras de código
Movimiento Humanoide Sin Tiempo de Espera
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- escucha cuando el humanoide alcanza su objetivo
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- comienza a caminar
humanoid:MoveTo(targetPoint)
-- ejecuta en un nuevo hilo para no bloquear la función
task.spawn(function()
while not targetReached do
-- ¿existe todavía el humanoide?
if not (humanoid and humanoid.Parent) then
break
end
-- ¿ha cambiado el objetivo?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresca el tiempo de espera
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- desconectar la conexión si aún está conectada
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "¡Destino alcanzado!") or "¡Falló en alcanzar el destino!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)Running
Parámetros
Muestras de código
Corriendo Humanoide
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function onRunning(speed: number)
if speed > 0 then
print(`{localPlayer.Name} está corriendo`)
else
print(`{localPlayer.Name} se ha detenido`)
end
end
humanoid.Running:Connect(function(speed: number)
onRunning(speed)
end)Seated
Muestras de código
Encontrando el asiento de un jugador
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local function onSeated(isSeated, seat)
if isSeated then
print("¡Ahora estoy sentado en: " .. seat.Name .. "!")
else
print("No estoy sentado en nada")
end
end
humanoid.Seated:Connect(onSeated)StateChanged
Parámetros
Muestras de código
Partículas Saltarinas
local character = script.Parent
local primaryPart = character.PrimaryPart
-- crear partículas
local particles = Instance.new("ParticleEmitter")
particles.Size = NumberSequence.new(1)
particles.Transparency = NumberSequence.new(0, 1)
particles.Acceleration = Vector3.new(0, -10, 0)
particles.Lifetime = NumberRange.new(1)
particles.Rate = 20
particles.EmissionDirection = Enum.NormalId.Back
particles.Enabled = false
particles.Parent = primaryPart
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
-- escuchar el estado del humanoide
local function onStateChanged(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
particles.Enabled = true
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
particles.Enabled = false
end
end
end
humanoid.StateChanged:Connect(onStateChanged)Enfriamiento de Salto
local character = script.Parent
local JUMP_DEBOUNCE = 1
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
task.wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)StateEnabledChanged
Parámetros
Muestras de código
Detector de Cambios de Estado del Humanoide
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local function onStateEnabledChanged(state, enabled)
if enabled then
print(state.Name .. " ha sido habilitado")
else
print(state.Name .. " ha sido deshabilitado")
end
end
humanoid.StateEnabledChanged:Connect(onStateEnabledChanged)StatusAdded
StatusRemoved
Touched
Muestras de código
Tocar de Midas
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local partInfo = {}
local debounce = false
local function onHumanoidTouched(hit, _limb)
if debounce then
return
end
if not hit.CanCollide or hit.Transparency ~= 0 then
return
end
if not partInfo[hit] then
partInfo[hit] = {
BrickColor = hit.BrickColor,
Material = hit.Material,
}
hit.BrickColor = BrickColor.new("Oro")
hit.Material = Enum.Material.Hielo
debounce = true
task.wait(0.2)
debounce = false
end
end
local touchedConnection = humanoid.Touched:Connect(onHumanoidTouched)
local function onHumanoidDied()
if touchedConnection then
touchedConnection:Disconnect()
end
-- deshacer todo el oro
for part, info in pairs(partInfo) do
if part and part.Parent then
part.BrickColor = info.BrickColor
part.Material = info.Material
end
end
end
humanoid.Died:Connect(onHumanoidDied)