Need help with script

Hello people I am making a piggy inspired game and I am working on the cutscene.
I made a post on how to do it eventually I got the solution but it wasn’t working for me.

Here is the script
Make sure to check the post if you want to understand.

This script clones the player and can see their character as the NPC.

local LocalNPC = game.Workspace.LocalNPC.Humanoid

game.Players.PlayerAdded:Connect(function(player)
	LocalNPC:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(player.UserId))
end)

There are no Output errors too.

Please help me. :slightly_frowning_face:

Edit : Really sorry for not linking the post.

1 Like

Well you didn’t leave a link to the post, but you can add a characteradded function after playeradded and have the applydescription in the middle. If not then just ignore characteradded and just use the variable line provided.

local LocalNPC = game.workspace:WaitForChild('LocalNPC'):FindFirstChild('Humanoid')

game.Players.PlayerAdded:Connect(function(player)
 player.CharacterAdded:Connect(function(char) -- or not
   LocalNPC:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(player.UserId))
end)
end)

Could you provide the link as well for context of what you want?

1 Like

First of all, you didn’t linked the post.
Second of all, we need more information like what is output saying, any error ?

WaitForChild is mainly used on the client, and FindFirstChild is used in if statements.

local Players = game:GetService('Players')
local Workspace = game:GetService('Workspace')

local NPC= Workspace.LocalNPC.Humanoid -- this will already exist,
-- and the dot operator is ~%20 faster than FindFirstChild.

Players.PlayerAdded:Connect(function(Player)
   Player.CharacterAdded:Connect(function(Character)
      NPC:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(player.UserId))
   end)
end)
1 Like

Is there an official source documenting this? Even so, the cost would be negligible, especially since Luau’s optimizes method calls.

Yes?..

Link: Instance:FindFirstChild.

1 Like

The wiki might be outdated, because the result is almost the same most of the time.

local part = script.Parent
local part2 = part.Part.Part

local start = os.clock()
for i = 1, 10000 do
    local a = part2:FindFirstChild("A")
end

print(os.clock()-start)

local start = os.clock()

for i = 1, 10000 do
    local a = part2.A
end

print(os.clock()-start)

image

It's even 2 times faster for recursive checks
local part = script.Parent
local start = os.clock()

for i = 1, 10000 do
     local a = part:FindFirstChild("A", true)
end

print(os.clock()-start)

local start = os.clock()

for i = 1, 10000 do
    local a = part.Part.Part.A
end

print(os.clock()-start)

image

Unfortunately it’s not my fault that the wiki might be outdated.
The Roblox API should provide correct information when needed.

However, I don’t think that they are wrong.

Also, FindFindChild is mainly used to check if something exists (if statement).
Using the dot operator works just fine in this case.

@daslick @BaconHair_Jacki and @others .
Sorry for not linking the post it was because of some network issues.
I mean really sorry :frowning:

There are no errors in the output

Is it just not cloning clothes?

I’ve never animated an NPC, but here is a snippet of code from where I clone a player’s character and put the clone on top of the player’s storage rack. Maybe it will help.


local myChar = player.Character or player.CharacterAdded:wait()
myChar.Archivable = true --!!! This is critical
local myCharClone = myChar:Clone()
myChar.Archivable = false
myCharClone.Parent = myStorageRack.ClonedCharFolder

Well I’ve tested it out before and had the same results. As for the if statements, yeah it’s used for if statements, but could it not also be used for this purpose? Either way, the code works just fine. dot or findfirstchild.

FindFirstChild doesn’t make sense like that, in my opinion no.
The dot operator works just fine, and is ~20% faster than using FindFirstChild.