How do i fix this problem? It keeps infinite yielding and not working
local root = CharacterClone:WaitForChild("HumanoidRootPart")
And HumanoidRootPart does exist on CharacterClone
How do i fix this problem? It keeps infinite yielding and not working
local root = CharacterClone:WaitForChild("HumanoidRootPart")
And HumanoidRootPart does exist on CharacterClone
Full code please?
I can’t know unless you provide more.
player.CharacterAdded:Connect(function(char)
for i, v in pairs(game.ReplicatedStorage:GetChildren()) do
if EquippedVal.Value == v.Name then
local CharacterClone = v:Clone()
print("Cloned")
CharacterClone.Name = player.Name
print(CharacterClone.Name)
local cframe = char.HumanoidRootPart.CFrame
player.Character:Destroy()
print("Destroyed")
player.Character = CharacterClone
print("Nearly")
local root = CharacterClone:WaitForChild("HumanoidRootPart") -- Error here
local hum = CharacterClone:WaitForChild("Humanoid")
wait()
root.CFrame = cframe
CharacterClone.Parent = game.Workspace
end
end
end)
You could use FindFirstChild instead of WaitForChild
Now it’s saying Attempt to index nil with CFrame
That is because you already tried to find it (using the dot operator assuming it exists already) above your WaitForChild.
the WaitForChild One was for the custom character and the cframe one was for the character, what do you mean?
The RootPart might not exist when the player’s character is added. Use WaitForChild.
Try setting the parent of “CharacterClone” To workspace before the :WaitForChild()
The solution should be to add a WaitForChild.
local cframe = char:WaitForChild('HumanoidRootPart').CFrame
Use root.CFrame = CFrame.new(cframe) instead of root.CFrame = cframe
Doesn’t matter, .CFrame already returns a CFrame, no need to create a CFrame inside a CFrame.
Add a wait() before parenting it the second time.
Ok got it(I think)
Wait for the character to be added to workspace before cloning it
What you are doing now is cloning a roblox locked object(The character is unlocked when added to workspace)
I had this exact problem before when messing with viewportframes and characters
I parent it to workspace 2 times?
Yes, the warning shows that based on experience, don’t mess with that. Don’t parent it yourself, roblox already does that, just use WaitForChild as I told you.
Im confused do i parent it 2 times in the script? Or do i just not use that and remove it?