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)
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?
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)
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)
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)
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.