ReplicatedFirst.LocalScript:13: attempt to index nil with 'HumanoidRootPart'

clone problem
script:

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()


UIS.InputBegan:Connect(function(Input,isTyping)
	if isTyping then return end
	if Input.KeyCode == Enum.KeyCode.E then

		local clone = char:Clone()

		print("working")
		clone.HumanoidRootPart.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, 0, 3)
		clone.Parent = workspace
	end
end)


local playerToClone = ""

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

local characterClone = clone(game.Players[playerToClone].Character)
characterClone.Parent = game.Workspace

Resource:

1 Like

heres a new brand btw this is a local script in playerscripts

script:

local UIS = game:GetService("UserInputService")
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Chr)
		UIS.InputBegan:Connect(function(Input)
			if Input.KeyCode == Enum.KeyCode.E then
				print("working")
		local clone = Chr:Clone()
				clone.Archivable= true 
				clone.HumanoidRootPart.CFrame = Chr.HumanoidRootPart.CFrame * CFrame.new(3.5, 0, -1.2) * CFrame.Angles(0, math.rad(90), 0)

				clone.Parent = workspace



				end
			end)
	end)
end)

idk why its not working
do i need remote event or somethin??

Since its a local script, you dont need to call the PlayerAdded and CharacterAdded events. You can easily get the player and character by just making variables.

Here is your updated code:

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")

local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")

UIS.InputBegan:Connect(function(input, typing)
	if typing then
		return
	end
	
	if input.KeyCode == Enum.KeyCode.E then
		local clone = char:Clone()
		clone.Archivable = true
		clone:WaitForChild("HumanoidRootPart").CFrame = hrp.CFrame * CFrame.new(3.5, 0, -1.2) * CFrame.Angles(0, math.rad(90),0)
		
		clone.Parent = workspace
		print("working!")
	end
end)
1 Like
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

userInput.InputBegan:Connect(function(Input, isTyping)
	if isTyping then return end

	if Input.KeyCode == Enum.KeyCode.E then
		character.Archivable = true
		local clone = character:Clone()
		clone.PrimaryPart.CFrame *= CFrame.new(0, 0, 3)
		clone.Parent = workspace
	end
end)

This is working for me.

1 Like