Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"CharacterAdded is not a valid member of Players?"

Asked by 5 years ago

How do i make a NPC look like a player ingame. I've done a ton of searching and seem to not get the answer. I'm trying to make it animated too at the same time.

Example: https://prnt.sc/kld0zl (a photo shows that a player is next to a model that looks just like them but without a hat.)

script:

game.Players.CharacterAdded.RBXScriptSignal:Connect():Connect(function(plr) local cchar = plr.Character:Clone() cchar:MoveTo(game.Workspace.charspawn.Position) cchar.HumanoidRootPart.Anchored = true end)

Error: CharacterAdded is not a valid member of Players

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You can check out the PlayerAdded event here. You must set the Archivable property to true before you can edit a players character.

local players = game:GetService("Players")

local function clone(character)
    character.Archivable = true
    local cloned = character:Clone()
    character.Archivable = false
    return cloned
end

local function move(clone, newpos)
    local torso = clone:FindFirstChild("HumanoidRootPart")
    -- make sure torso is there
    if torso then 
        torso.Anchored = true
        clone:MoveTo(newpos)
        -- move clone
    end
end

players.PlayerAdded:Connect(function(player)
    -- When a player joins
    player.CharacterAdded:Connect(function(character)
        -- When a players character loads 
        delay(player.DataReady, function() 
        -- seems to help wait for everything to load
        local clonedCharacter = clone(character)
        -- clone it
        clonedCharacter.Parent = workspace
        -- parent it
        move(clonedCharacter,  Vector3.new(0,5,30) ) end)
        -- move it
    end)
end)
0
there's a way to animate it right? TheBuliderMC 84 — 5y
0
Yes, look up how to load NPC animations. There are relevant tutorials on SH, the dev forum, and on YouTube.  Azarth 3141 — 5y
Ad

Answer this question