gamedev-skills/awesome-gamedev-agent-skills

roblox-characters

Build respawn-safe Roblox character systems around Players, CharacterAdded/CharacterRemoving, Humanoid, HumanoidRootPart, Animator, R6/R15 rigs, movement, animations and markers, death, tools, accessories, ownership, and custom characters.

查看源码
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

Roblox characters

Treat a Player as the durable identity and each Character as a replaceable session with its own references, connections, animation tracks, and cleanup. Targets Roblox's rolling platform APIs.

When to use

  • Use for player-character lifecycle, Humanoid state/movement, rigs, animations, tools,

accessories, custom characters, death, or respawn defects.

  • Use whenever code stores a Character/Humanoid/root reference longer than one spawn.

When not to use: general physics queries and constraints belong to roblox-physics; remote trust belongs to roblox-networking; camera logic belongs to camera-systems.

Workflow

  1. Inspect the character contract. Check avatar settings, StarterCharacter,

StarterCharacterScripts, CharacterAutoLoads, R6/R15 support, existing Animate/controller scripts, tools, tags, collision groups, and server/client ownership.

  1. Separate scopes. Player-scope state survives respawn; character-scope state does not. Put

character connections/tracks/resources in one cleanup scope and destroy it on removal.

  1. Bind existing and future characters. Connect CharacterAdded, then bind player.Character

if present. Do not assume event subscription alone sees a character that already spawned.

  1. Resolve required components defensively. Wait with a timeout where replication warrants it;

validate Humanoid, root, Animator, and rig assumptions. Abort if that character is no longer current before applying delayed work.

  1. Choose movement ownership. Use Humanoid movement for standard avatars; use

AssemblyLinearVelocity, BasePart:ApplyImpulse(), or a LinearVelocity/AlignPosition constraint only for mechanics that need physical control. Keep gameplay authority and network ownership implications explicit.

  1. Own animation lifecycle. Load via the rig's Animator; store tracks/connections; use named

markers for gameplay timing only with server validation; stop/disconnect on character cleanup.

  1. Verify lifecycle stress. Spawn, die, reset, rapid-respawn, swap rig if supported, equip/drop

tools, leave during setup, and run with at least two players when character interactions matter.

Pattern: replaceable character scope

lua
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local generation = 0
local connections: {RBXScriptConnection} = {}
local currentCharacter: Model? = nil

local function clearCharacter()
    generation += 1
    for _, connection in connections do connection:Disconnect() end
    table.clear(connections)
    currentCharacter = nil
end

local function bindCharacter(character: Model)
    -- Guard BEFORE teardown. A stale invocation (see the CharacterAdded/defer race below) must not
    -- clear a binding that is already current, or nothing ends up bound at all.
    if player.Character ~= character then return end
    clearCharacter()
    currentCharacter = character
    local thisGeneration = generation
    local humanoid = character:WaitForChild("Humanoid", 10)
    local root = character:WaitForChild("HumanoidRootPart", 10)
    -- Re-check after the yields: a respawn during WaitForChild bumps generation and makes this call stale.
    if not humanoid or not root or generation ~= thisGeneration then return end

    table.insert(connections, humanoid.Died:Connect(function()
        if generation ~= thisGeneration then return end
        setCharacterUiEnabled(false)
    end))
    attachCurrentCharacterSystems(character, humanoid, root)
end

player.CharacterRemoving:Connect(function(character)
    if currentCharacter == character then clearCharacter() end
end)
player.CharacterAdded:Connect(bindCharacter)
if player.Character then task.defer(bindCharacter, player.Character) end

Use the project's cleanup utility when one exists; do not introduce a new framework for three connections. Server systems repeat this binding per Player and clear player-scope tables on PlayerRemoving.

Pattern: animation through Animator and markers

lua
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://1234567890"
local track = animator:LoadAnimation(animation)
local markerConnection = track:GetMarkerReachedSignal("Commit"):Connect(function(parameter)
    playLocalSwingEffect(parameter) -- presentation; server still validates any hit
end)

track:Play(0.1)
-- On character teardown:
markerConnection:Disconnect()
track:Stop(0.1)
animation:Destroy()

For rigs without a Humanoid, use an AnimationController with an Animator. Do not use the deprecated convenience path as a substitute for owning the actual Animator and track lifecycle.

Movement and rig rules

  • Do not hardcode R15 limb names if R6 is supported. Prefer attachments, tags, or a rig-type

adapter; branch on Humanoid.RigType only where topology materially differs.

  • HumanoidRootPart is the usual character assembly root, not a universal guarantee for every

custom model. Define the custom rig contract and validate it at spawn.

  • Prefer Humanoid:Move()/standard controls for ordinary avatar locomotion. Directly changing

AssemblyLinearVelocity is an instantaneous physical action; use forces/constraints or impulses when continuous or instantaneous physics is the real intent.

  • Never grant damage or movement authority because a client owns its character physics. Validate

cross-player consequences on the server.

  • Tools move between Backpack and Character during equip; listen to lifecycle/state rather than

assuming one fixed parent. Modify accessories/appearance through current character APIs and preserve an up-to-date applied HumanoidDescription when editing avatar appearance.

Common failures

SymptomLikely causeRemedy
works once, breaks after resetcached character/Humanoid/rootrebuild per CharacterAdded; clear on removal
callbacks fire twice after deathsold character connections survivedcharacter-scoped cleanup and generation/current checks
delayed load edits wrong rigasync work outlived spawncompare current Character/generation after every yield
animation visible only locally or not at allwrong Animator/context/asset ownershipinspect rig Animator, execution side, permissions, and replication
hit marker awards impossible hitanimation marker trusted as authorityuse marker for timing/presentation; server validates combat state
R6/custom rig errorsR15 names assumeddefine rig contract; attachments/adapter; test each supported rig
tool disappears from systemfixed Backpack/Character parent assumedhandle equip/unequip ancestry and character replacement
custom force fights Humanoidtwo controllers own motionchoose one movement authority per state and restore cleanly

Resources

  • Read references/lifecycle-and-animation.md for server binding, death vs removal, rig and

animation verification, custom characters, and the lifecycle stress matrix.

Related skills

  • roblox-physics — forces, constraints, assemblies, collision, and network ownership.
  • roblox-networking — server validation of character actions and stale requests.
  • input-systems — action mapping and responsive movement intent.
  • camera-systems — camera behavior following replaceable characters.

Primary references

  • https://create.roblox.com/docs/characters
  • https://create.roblox.com/docs/animation/using
  • https://create.roblox.com/docs/characters/appearance
来自同一仓库

更多 Skills

全部 Skills
gamedev-skills
社区

roblox-ui

Build production Roblox interfaces with ScreenGui/PlayerGui lifecycle, responsive UDim2 layouts, safe insets, reusable editable Instances, cross-device input and selection, restrained motion, cleanup, and multi-viewport verification. Use for Roblox HUDs, inventories, shops, settings, ability bars, ScrollingFrames, AutomaticSize, GuiService, gamepad focus, touch UI, or UI that clips, resets on respawn, looks generic, or was generated as one giant LocalScript.

安装量
4
GitHub Stars
1477
最近更新
10月9日
gamedev-skills
社区

shader-programming

Write game shaders from cross-engine fundamentals — the vertex→fragment pipeline, coordinate spaces, UV math, and common 2D/3D effects (tint, UV scroll, dissolve, outline, fresnel rim, vignette) in GLSL with HLSL equivalents. Use when the user mentions shaders, fragment/pixel shader, vertex shader, UV, GLSL, HLSL, or effects like dissolve, outline, or rim light.

安装量
5
GitHub Stars
1396
最近更新
10月9日
gamedev-skills
社区

dialogue-systems

Build branching dialogue and narrative — a node/choice graph with conditions, variables, and localization hooks — and choose between authoring tools Ink and Yarn Spinner or a custom data-driven runner. Engine-neutral. Use when the user mentions dialogue system, branching dialogue, conversation tree, choices, Ink (.ink), Yarn Spinner (.yarn), or NPC dialogue.

安装量
5
GitHub Stars
1396
最近更新
10月9日
gamedev-skills
社区

godot-2d-movement

Implement 2D kinematic character movement in Godot 4.7 with CharacterBody2D and moveandslide(): platformer run/jump with gravity, top-down 8-direction motion, slope handling, and reading collisions. Use when coding a 2D player or enemy controller, a platformer or top-down character, or fixing moveandslide()/ isonfloor() behavior in a .tscn with a CharacterBody2D.

安装量
1
GitHub Stars
1382
最近更新
10月9日