Humanoid
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
Humanoid to specjalny obiekt, który daje modelem funkcjonalność postaci.Zapewnia modelowi możliwość fizycznego chodzenia i interakcji z różnymi komponentami doświadczenia Roblox.Humanoidy zawsze są rodzicami w środku Model, a model jest oczekiwany jako zbiór BasePart i Motor6D, korzeń części zbioru ma być nazwany HumanoidRootPart.Oczekuje również, że część o nazwie Head zostanie połączona z częścią tułowia postaci bezpośrednio lub pośrednio.Domyślnie istnieją dwa oficjalne rodzaje postaci dostarczane przez Roblox, każdy z własnym zestawem zasad:
R6
- Podstawowa rama postaci, która używa 6 części do kończyn.
- Część Head musi być przymocowana do części o nazwie Torso, lub Humanoid natychmiast umrze.
- Występy części ciała są stosowane za pomocą obiektów CharacterMesh.
- Niektóre właściwości, takie jak Humanoid.LeftLeg i Humanoid.RightLeg, działają tylko z R6.
R15
- Bardziej skomplikowany niż R6, ale również dużo bardziej elastyczny i wytrzymały.
- Używa 15 części dla kończyn.
- Część Head musi być przymocowana do części o nazwie UpperTorso lub Humanoid natychmiast umrze.
- Występy części ciała muszą być złożone bezpośrednio.
- Można dynamicznie skalować za pomocą specjalnych obiektów NumberValue wewnątrz Humanoida.
- Humanoid automatycznie stworzy obiekty Vector3Value o nazwie OriginalSize wewnątrz każdej kończyny.
- Jeśli wartość liczbowa jest powiązana wewnątrz Humanoida i nazywa się jedną z obserwuje, zostanie ona wykorzystana do kontroli funkcjonalności skalowania:
- Skala głębi ciała
- Skala wysokości ciała
- Skala szerokości ciała
- Skala głowy
Przykłady kodu
This LocalScript makes the camera bobble as the player's character walks around, utilizing both the Humanoid's CameraOffset and MoveDirection. It should be parented inside of the StarterCharacterScripts so that it is distributed into a player's character as expected.
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 -- Is the character walking?
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
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
Podsumowanie
Właściwości
Ustawia, czy postać automatycznie skoczy, gdy trafi na przeszkodę jako gracz na urządzeniemobilnym.
Automatyczne obroty ustawiają, czy ludzik będzie automatycznie obracać się w kierunku, w którym się porusza.
Gdy włączone, AutomaticScalingEnabled powoduje, że rozmiar postaci zmienia się w odpowiedzi na zmiany wartości skali dziecka humanoida.
Określa, czy stawy humanoida pękają, gdy znajduje się w stanie Enum.HumanoidStateType.Dead.
Odległość zastosowana do pozycji tematu kamery, gdy jej temat kamery jest ustawiony na tego humanoida.
Kontroluje zachowanie dystansu nazwy i wyświetlania zdrowia humanoida.
Ustawia tekst humanoida, wyświetlany nad jego głową.
Opisuje Enum.Material, na którym obecnie stoi Humanoid.Jeśli Humanoid nie stoi na czymkolwiek, wartość tej właściwości będzie Powietrze.
Opisuje obecne zdrowie Humanoida na odległości [0, Humanoid.MaxHealth].
Używany w połączeniu z właściwością DisplayDistanceType w celu kontrolowania odległości, z której można zobaczyć pasek zdrowia humanoida.
Sposób kontroli, kiedy pasek zdrowia humanoida może być wyświetlany.
Określa odległość od ziemi, jaką powinien mieć Humanoid.RootPart .
Jeśli true , skoki Humanoid wykonują siłą w górę.
Zapewnia kontrolę nad wysokością, na którą skacze Humanoid skok.
Określa, ile siły w górę jest stosowane do Humanoid podczas skoku.
Maksymalna wartość humanoida Health .
Maksymalny kąt nachylenia, na którym człowiek może chodzić bez poślizgu.
Opisuje kierunek, w którym podąża Humanoid .
Używany w połączeniu z właściwością Humanoid.DisplayDistanceType w celu kontrolowania odległości, z której można zobaczyć nazwę humanoida.
Kontroluje, czy nazwa i pasek zdrowia humanoida może być widoczny za ścianami lub innymi obiektami.
Określa, czy Humanoid jest obecnie w stanie Enum.HumanoidStateType.PlatformStanding.
Pozwala programistom wyłączyć zachowanie, w którym gracz Character|character umiera, jeśli szyja Motor6D zostanie usunięta lub odłączona choćby na chwilę.
Opisuje, czy to Humanoid wykorzystuje dziedziczonego postaci R6, czy nową postać R15.
Odwołanie do obiektu HumanoidRootPart ludzkiegooidu.
Odniesienie do siedzenia, na którym obecnie siedzi Humanoid, jeśli takie istnieje.
Opisuje, czy Humanoid jest obecnie siedzący.
Opisuje pozycję 3D, w której Player kontroluje Humanoid ostatnio kliknięte w świecie za pomocą Tool.
Określa, czy używana jest właściwość JumpHeight (fałsz) lub Humanoid.JumpPower (prawda).
Opisuje maksymalną prędkość ruchu humanoida w studach na sekundę.
Odniesienie do części, której pozycja jest próbować osiągnąć przez humanoida
Pozycja, do której próbuje dotrzeć humanoid, po wykonaniu wezwania do Humanoid:MoveTo().
Metody
Przyłącza określone Accessory do rodzica humanoida.
Zbiera drzewo Motor6D połączeń poprzez przymocowanie razem Attachment obiektów w charakterze humanoida.
Ustawia Humanoid na wejście do podanego Enum.HumanoidStateType.
Zwraca arkusz z Accessory obiektami, które nosi obecnie rodzic humanoida.
Zwraca kopię zapamiętanego HumanoidDescription obrazu, który opisuje jego obecny wygląd.
Przekaż część ciała do tej metody (część ciała powinna być siostrą Humanoida i dzieckiem modelu) aby uzyskać Enum.BodyPartR15 z Part.
Zwraca Enum.Limb enumerację, która jest powiązana z danym Part.
Zwraca obecną Enum.HumanoidStateType ludzkiegooida.
Zwraca, czy Enum.HumanoidStateType jest włączone dla Humanoid.
Spowoduje, że Humanoid chodzi w określonym kierunku.
Spowoduje, że Humanoid próbuje przejść do określonej lokalizacji, ustawiając właściwości Humanoid.WalkToPoint i Humanoid.WalkToPart.
Usuwa wszystkie Accessory obiekty noszone przez rodzica humanoida
Automatycznie zastępuje część ciała ludzkiego humanoida inną częścią.
Ustawia, czy dane Enum.HumanoidStateType jest włączone dla Humanoid.
Obniża Humanoid.Health z Humanoid o podanych kwotę jeśli nie jest chroniona przez ForceField.
- ApplyDescription(humanoidDescription : HumanoidDescription,assetTypeVerification : Enum.AssetTypeVerification):()
Tworzy wygląd postaci pasujący do przekazanego w HumanoidDescription .
- ApplyDescriptionReset(humanoidDescription : HumanoidDescription,assetTypeVerification : Enum.AssetTypeVerification):()
Rektyfikuje wygląd postaci do wyglądu przekazanego w HumanoidDescription, nawet po zmianach zewnętrznych.
Odtwarza emotki i zwraca, jeśli zostały pomyślnie uruchomione.
Zdarzenia
Wybucha, gdy prędkość, z jaką wzrasta Humanoid zmienia się.
Wypala się, gdy Humanoid umiera.
Wypala się, gdy Humanoid wchodzi lub wychodzi z FallingDown``Enum.HumanoidStateType.
Wypala się, gdy Humanoid wchodzi lub wychodzi z Freefall``Enum.HumanoidStateType.
Wypala się, gdy Humanoid wchodzi lub wychodzi z GettingUp``Enum.HumanoidStateType.
Wypala się, gdy zmienia się Humanoid.Health lub gdy ustawiono Humanoid.MaxHealth .
Wypala się, gdy Humanoid wchodzi i opuszcza Jumping``Enum.HumanoidStateType .
Wypala się, gdy Humanoid kończy chód do celu ogłoszonego przez Humanoid:MoveTo().
Wypala się, gdy Humanoid wchodzi lub wychodzi z PlatformStanding``Enum.HumanoidStateType.
Wypala się, gdy Humanoid wchodzi lub wychodzi z Ragdoll``Enum.HumanoidStateType.
Wybucha, gdy prędkość, z jaką działa Humanoid , zmienia się.
Wystrzeliwany, gdy Humanoid siedzi w Seat lub VehicleSeat lub wstaje.
Wypala się, gdy zmieni się stan Humanoid.
Wypala się, gdy Humanoid:SetStateEnabled() jest wzywany na Humanoid.
Wypala się, gdy Humanoid wchodzi lub wychodzi z StrafingNoPhysics``Enum.HumanoidStateType.
Wypala się, gdy prędkość, z jaką pływa Humanoid w wodzie zmienia się Terrain.
Wypala się, gdy jedna z kończyn humanoida wchodzi w kontakt z inną BasePart.
Właściwości
AutoJumpEnabled
Przykłady kodu
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
local function update()
-- Aktualizuj tekst przycisku
if player.AutoJumpEnabled then
button.Text = "Auto-Jump is ON"
else
button.Text = "Auto-Jump is OFF"
end
-- Odbij właściwość w postaci gracza, jeśli ma jedną
if player.Character then
local human = player.Character:FindFirstChild("Humanoid")
if human then
human.AutoJumpEnabled = player.AutoJumpEnabled
end
end
end
local function onActivated()
-- Przełącz automatyczne skakanie
player.AutoJumpEnabled = not player.AutoJumpEnabled
-- Zaktualizuj wszystko inne
update()
end
button.Activated:Connect(onActivated)
update()
AutoRotate
Przykłady kodu
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() .. " can no longer auto-rotate!")
humanoid.AutoRotate = false
else
print(humanoid:GetFullName() .. " can now auto-rotate!")
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_COLOR
AutomaticScalingEnabled
BreakJointsOnDeath
CameraOffset
Przykłady kodu
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 -- Is the character walking?
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
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
DisplayDistanceType
Przykłady kodu
local humanoid = script.Parent
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
humanoid.HealthDisplayDistance = 0
humanoid.NameDisplayDistance = 100
DisplayName
EvaluateStateMachine
FloorMaterial
Health
HealthDisplayDistance
HealthDisplayType
HipHeight
Jump
JumpHeight
JumpPower
MaxHealth
MaxSlopeAngle
Przykłady kodu
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local h = char:FindFirstChild("Humanoid")
h.MaxSlopeAngle = 30
MoveDirection
Przykłady kodu
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 -- Is the character walking?
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
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
RunService.RenderStepped:Connect(updateBobbleEffect)
NameDisplayDistance
NameOcclusion
Przykłady kodu
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)
PlatformStand
RequiresNeck
RigType
RootPart
SeatPart
Sit
TargetPoint
UseJumpPower
WalkSpeed
WalkToPart
WalkToPoint
Przykłady kodu
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)
Metody
AddAccessory
Parametry
Zwroty
Przykłady kodu
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)
BuildRigFromAttachments
Zwroty
Przykłady kodu
local function createJoint(jointName, att0, att1)
local part0, part1 = att0.Parent, att1.Parent
local newMotor = part1:FindFirstChild(jointName)
if not (newMotor and newMotor:IsA("Motor6D")) then
newMotor = Instance.new("Motor6D")
end
newMotor.Name = jointName
newMotor.Part0 = part0
newMotor.Part1 = part1
newMotor.C0 = att0.CFrame
newMotor.C1 = att1.CFrame
newMotor.Parent = part1
end
local function buildJointsFromAttachments(part, characterParts)
if not part then
return
end
-- first, loop thru all of the part's children to find attachments
for _, attachment in pairs(part:GetChildren()) do
if attachment:IsA("Attachment") then
-- only do joint build from "RigAttachments"
local attachmentName = attachment.Name
local findPos = attachmentName:find("RigAttachment")
if findPos then
-- also don't make double joints (there is the same named
-- rigattachment under two parts)
local jointName = attachmentName:sub(1, findPos - 1)
if not part:FindFirstChild(jointName) then
-- try to find other part with same rig attachment name
for _, characterPart in pairs(characterParts) do
if part ~= characterPart then
local matchingAttachment = characterPart:FindFirstChild(attachmentName)
if matchingAttachment and matchingAttachment:IsA("Attachment") then
createJoint(jointName, attachment, matchingAttachment)
buildJointsFromAttachments(characterPart, characterParts)
break
end
end
end
end
end
end
end
end
local function buildRigFromAttachments(humanoid)
local rootPart = humanoid.RootPart
assert(rootPart, "Humanoid has no HumanoidRootPart.")
local characterParts = {}
for _, descendant in ipairs(humanoid.Parent:GetDescendants()) do
if descendant:IsA("BasePart") then
table.insert(characterParts, descendant)
end
end
buildJointsFromAttachments(rootPart, characterParts)
end
local humanoid = script.Parent:WaitForChild("Humanoid")
buildRigFromAttachments(humanoid)
local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")
local PACKAGE_ASSET_ID = 193700907 -- Circuit Breaker
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:GetProductInfo(packageAssetId)
local character, humanoid = createBaseCharacter()
character.Name = packageAssetInfo.Name
local assetIds = AssetService:GetAssetIdsForPackage(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 = workspace
ChangeState
Parametry
Zwroty
Przykłady kodu
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
Zwroty
Przykłady kodu
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)
GetLimb
Parametry
Zwroty
Przykłady kodu
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 .. " is part of limb " .. limb.Name)
end
end
GetState
Zwroty
Przykłady kodu
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
Parametry
Zwroty
Przykłady kodu
local humanoid = script.Parent:WaitForChild("Humanoid")
-- Set state
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
-- Get state
print(humanoid:GetStateEnabled(Enum.HumanoidStateType.Jumping)) -- false
Move
Parametry
Zwroty
Przykłady kodu
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
Parametry
Zwroty
Przykłady kodu
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)
RemoveAccessories
Zwroty
Przykłady kodu
local Players = game:GetService("Players")
local function onPlayerAddedAsync(player)
local connection = player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local humanoid = character:FindFirstChildOfClass("Humanoid")
local numAccessories = #humanoid:GetAccessories()
print(("Destroying %d accessories for %s"):format(numAccessories, player.Name))
humanoid:RemoveAccessories()
end)
-- Make sure we disconnect our connection to the player after they leave
-- to allow the player to get garbage collected
player.AncestryChanged:Wait()
connection:Disconnect()
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAddedAsync, player)
end
Players.PlayerAdded:Connect(onPlayerAddedAsync)
ReplaceBodyPartR15
Parametry
Zwroty
SetStateEnabled
Parametry
Zwroty
Przykłady kodu
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
Parametry
Zwroty
Przykłady kodu
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)
UnequipTools
Zwroty
ApplyDescription
Parametry
Zwroty
ApplyDescriptionReset
Parametry
Zwroty
Zdarzenia
Climbing
Parametry
Przykłady kodu
local Players = game:GetService("Players")
local function onCharacterClimbing(character, speed)
print(character.Name, "is climbing at a speed of", speed, "studs / second.")
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)
Died
Przykłady kodu
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local function onDied()
print(player.Name, "has died!")
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
HealthChanged
Parametry
Przykłady kodu
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("The humanoid's health", (currentHealth > health and "decreased by" or "increased by"), change)
currentHealth = health
end
humanoid.HealthChanged:Connect(onHealthChanged)
end
player.CharacterAdded:Connect(onCharacterAdded)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Paste script into a LocalScript that is
-- parented to a Frame within a Frame
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0) -- black
-- This function is called when the humanoid's health changes
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
-- Change the size of the inner bar
frame.Size = UDim2.new(percent, 0, 1, 0)
-- Change the color of the health bar
if percent < 0.1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0) -- black
elseif percent < 0.4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0) -- yellow
else
frame.BackgroundColor3 = Color3.new(0, 1, 0) -- green
end
end
-- This function runs is called the player spawns in
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
-- Pattern: update once now, then any time the health changes
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
-- Connect our spawn listener; call it if already spawned
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end
MoveToFinished
Parametry
Przykłady kodu
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen(reached)
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
task.spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
task.wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end
local function andThen(reached)
print((reached and "Destination reached!") or "Failed to reach destination!")
end
moveTo(script.Parent:WaitForChild("Humanoid"), Vector3.new(50, 0, 50), andThen)
Running
Parametry
Przykłady kodu
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} is running`)
else
print(`{localPlayer.Name} has stopped`)
end
end
humanoid.Running:Connect(function(speed: number)
onRunning(speed)
end)
Seated
Parametry
Przykłady kodu
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local function onSeated(isSeated, seat)
if isSeated then
print("I'm now sitting on: " .. seat.Name .. "!")
else
print("I'm not sitting on anything")
end
end
humanoid.Seated:Connect(onSeated)
StateChanged
Parametry
Przykłady kodu
local character = script.Parent
local primaryPart = character.PrimaryPart
-- create particles
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
-- listen to humanoid state
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)
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
Parametry
Przykłady kodu
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 .. " has been enabled")
else
print(state.Name .. " has been disabled")
end
end
humanoid.StateEnabledChanged:Connect(onStateEnabledChanged)
Touched
Parametry
Przykłady kodu
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("Gold")
hit.Material = Enum.Material.Ice
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
-- undo all of the gold
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)