For some reason it keeps erroring out and giving me this message
Players.YouShalllNotPass.Backpack.FuncDeath:5 : Attempt to index field 'Character' (a nil Value)
IT IS A LOCALSCRIPT
here's my script :
local character = game.Players.LocalPlayer.Character local player = game.Players.LocalPlayer local char = game.Players.LocalPlayer.Character game.Players.LocalPlayer.Character.Humanoid.Changed:connect(function(death) if game.Players.LocalPlayer.Character.Humanoid.Health == 0 then local i = game.ServerStorage.Death:Clone() local o = game.ServerStorage.Death:Clone() local p = game.ServerStorage.Death:Clone() local a = game.ServerStorage.Death:Clone() local s = game.ServerStorage.Death:Clone() local d = game.ServerStorage.Death:Clone() i.Parent = character.Torso o.Parent = character:findFirstChild("Right Arm") p.Parent = character:findFirstChild("Right Leg") a.Parent = character:FindFirstChild("Left Arm") s.Parent = character:FindFirstChild("Left Leg") -- Limbs Disappear character:findFirstChild("Right Arm").Transparency = 1 character:findFirstChild("Right Leg").Transparency = 1 character:FindFirstChild("Left Arm").Transparency = 1 character:FindFirstChild("Left Leg").Transparency = 1 -- Clothing Disappear if char:FindFirstChild("Pants") then char.Pants:Destroy() if char:FindFirstChild("Shirt") then char.Shirt:Destroy() if char:FindFirstChild("Hat") then char.Hat:Destroy() if char:FindFirstChild("Hat") then char.Hat:Destroy() if char:FindFirstChild("Hat") then char.Hat:Destroy() end end end end end end end)
"LocalPlayer" is always nil to a server script. Is this a Script or a LocalScript? If it's a Script, you need to find some other way to get a reference to the player object.
EDIT: So the problem is that the Character has not spawned yet. This code checks waits for the character to spawn. If the character's parent is nil, it means that the LocalScript ran before the old character was removed, so you need to wait for the new character to spawn.
local player = game.Players.LocalPlayer local character = Player.Character if not character or character.Parent == nil then character = player.CharacterAdded:wait() end --now the character exists
You can't access ServerStorage from a LocalScript, Put the objects in ReplicatedStorage instead.
The hidden variable LocalPLayer, can only be accessed on the Client * therefore *LocalPlayer can accessed only be accessed on the Client! To access what the Client sees, Use the code in a Local Script!
I see you have to access the ServerStorage which can only be accessed by Scripts or Server-Sided Scripts. You may have to go to the Roblox Wiki and manually search! I'll try to hep you though!
References:
LocalPlayer = Player in the Client Side
Client = Your computer
Local Script = Scripts that only run and affect client-sided objects on Client
Server Storage = A storage system that is useful for maps(Replacement for using Lighting as Storage
Server-Sided Script = A script that runs on the server and cannot be accessed by Client