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