Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why does the output say that "Character" is a nil value?

the script that i'm making is supposed to clone each body part, however before even starting to code this script the output says "attempt to index local 'Character' (a nil value)"

what is wrong with this script? i've tried multiple solutions with no outcome.

-- transform script

local player = game.Players.LocalPlayer
local mouse = script.Parent.Parent:GetMouse()
local Character = player.Character 

local transformed = Instance.new("BoolValue")
transformed.Name = "Transformed"
transformed.Value = false
transformed.Parent = script

-- body parts

local LUarm = Character.LeftUpperArm
local LLarm = Character.LeftLowerArm
local Lhand = Character.LeftHand
local RUarm = Character.RightUpperArm
local RLarm = Character.RightLowerArm
local Rhand = Character.RightHand
local utorso = Character.UpperTorso
local ltorso = Character.LowerTorso
local LUleg = Character.LeftUpperLeg
local LLleg = Character.LeftLowerLeg
local Lfoot = Character.LeftFoot
local RUleg = Character.RightUpperLeg
local RLleg = Character.RightLowerLeg
local Rfoot = Character.RightFoot
local head = Character.Head
local hroot = Character.HumanoidRootPart

local CLUarm = Character.LeftUpperArm:Clone()
local CLLarm = Character.LeftLowerArm:Clone()
local CLhand = Character.LeftHand:Clone()
local CRUarm = Character.RightUpperArm:Clone()
local CRLarm = Character.RightLowerArm:Clone()
local CRhand = Character.RightHand:Clone()
local Cutorso = Character.UpperTorso:Clone()
local Cltorso = Character.LowerTorso:Clone()
local CLUleg = Character.LeftUpperLeg:Clone()
local CLLleg = Character.LeftLowerLeg:Clone()
local CLfoot = Character.LeftFoot:Clone()
local CRUleg = Character.RightUpperLeg:Clone()
local CRLleg = Character.RightLowerLeg:Clone()
local CRfoot = Character.RightFoot:Clone()
local Chead = Character.Head:Clone()
local Chroot = Character.HumanoidRootPart:Clone()

2 comments

0

Every answer doesn't work. This is amazing.

0

 Check my answer. I have tested it, and its fully functional.

4 answers

✓ Accepted answer

Hi, Your script is being run before the Character spawns in the game, as such, Character is a nil value. To fix this, you should wait until the players character is added into the game like so:

local character = player.Character or player.CharacterAdded:wait()

Full code:

-- transform script

-- transform script

local player = game.Players.LocalPlayer
local mouse = script.Parent.Parent:GetMouse()
local Character = player.Character or player.CharacterAdded:wait()

local transformed = Instance.new("BoolValue")
transformed.Name = "Transformed"
transformed.Value = false
transformed.Parent = script

-- body parts

local LUarm = Character:WaitForChild("LeftUpperArm")
local LLarm = Character:WaitForChild("LeftLowerArm")
local Lhand = Character:WaitForChild("LeftHand")
local RUarm = Character:WaitForChild("RightUpperArm")
local RLarm = Character:WaitForChild("RightLowerArm")
local Rhand = Character:WaitForChild("RightHand")
local utorso = Character:WaitForChild("UpperTorso")
local ltorso = Character:WaitForChild("LowerTorso")
local LUleg = Character:WaitForChild("LeftUpperLeg")
local LLleg = Character:WaitForChild("LeftLowerLeg")
local Lfoot = Character:WaitForChild("LeftFoot")
local RUleg = Character:WaitForChild("RightUpperLeg")
local RLleg = Character:WaitForChild("RightLowerLeg")
local Rfoot = Character:WaitForChild("RightFoot")
local head = Character:WaitForChild("Head")
local hroot = Character:WaitForChild("HumanoidRootPart")

local CLUarm = Character.LeftUpperArm:Clone()
local CLLarm = Character.LeftLowerArm:Clone()
local CLhand = Character.LeftHand:Clone()
local CRUarm = Character.RightUpperArm:Clone()
local CRLarm = Character.RightLowerArm:Clone()
local CRhand = Character.RightHand:Clone()
local Cutorso = Character.UpperTorso:Clone()
local Cltorso = Character.LowerTorso:Clone()
local CLUleg = Character.LeftUpperLeg:Clone()
local CLLleg = Character.LeftLowerLeg:Clone()
local CLfoot = Character.LeftFoot:Clone()
local CRUleg = Character.RightUpperLeg:Clone()
local CRLleg = Character.RightLowerLeg:Clone()
local CRfoot = Character.RightFoot:Clone()
local Chead = Character.Head:Clone()
local Chroot = Character.HumanoidRootPart:Clone()

14 comments

0

i've tried all these answers and it doesn't seem to be a solution to the problem. which then leads me to the question, if the problem is the character loading in, how come these don't work? and if you do have another solution, i'd love to know!

0

Sorry, change character to Character

0

Sorry, change character to Character

0

let me try again.

0

Ok I just added some WaitForChild()'s and edited my code. Should work this time.

0

The WaitForChild() method won't fix the problem. The problem is the character itself being nil along with its children.

0

what do you mean? what do you suggest the solution might be? im stuck on this

0

Where is your script located?

0

It's impossible for the Character to be nil using my method, lol. Assuming he's using the R16 rig, my method is 100% functional... I tested it myself.

0

in the starterpack. I am trying to create all these variables and after they all load i am going to make key function that will use these body parts.

0

Put my code in the StarterPack and it should work.(It will work)

0

Also, why aren't you using the variables you created when cloning lol

0

i just noticed that and im fixing it right now haha, after let me check.

0

thanks so much! im glad there are people like you who are dedicated to help. appreciate it. thanks man!

The character hasn't loaded in yet, therefore your attempt at addressing the player's character comes out as nil. To fix this, simply add a wait at the beginning of your script, or better yet utilize the CharacterAdded event to run your code once the character actually loads in.

1 comment

0

it's a bit odd. the wait function doesn't work, nor does the characteradded.

This may seem improper to do, but im going to assume that you have a local script, inside StarterGui..

I would add a wait() before getting Character's body parts.

Hope this works!

I think you are using a server-side Script instead of a local script. It will say that when you are trying to access player-specific objects with a server-script. Try using a LocalScript instead, and I hope it will be fine.

If you are already using a LocalScript and it still does not work, try using :Wait() because the character may have not been loaded.

This discussion is preserved as it was. New answers, comments, and votes are closed.