Ok,so I decided to make a script of mine into a local script and it seems to act odd. It fails at making the welds and destroying the left arm at death in solo.Every time I start a sever with 2 players it get an error saying:
Players.Player1.PlayerGui.LocalScript:10: attempt to index global 'Character' (a nil value)
which I don't get because I have a variable called Character at line 2.Oh,and this seems to work find when I put it in a regular script,why and how do I fix all these problems?
LocalScript:
Player = game.Players.LocalPlayer local Character = Player.Character if not Character or Character.Parent == nil then Character = Player.CharacterAdded:wait() --------------------------------------------------------- Player.CameraMode= Enum.CameraMode.LockFirstPerson --------------------------------------------------------- function MakeDisplayArms() --------------------------------------------------------- local CurrentCamera = game.Workspace.CurrentCamera local PlayerArms = { Character:WaitForChild("Right Arm"), Character:WaitForChild("Left Arm")} local ClonedArms = {} --------------------------------------------------------- for i,v in pairs (PlayerArms) do wait() local Clone = v:Clone() Clone.Name = "Cloned_"..v.Name --Renames it Clone.CanCollide = true local Weld = Instance.new("Weld",Clone) Weld.Part0 = Clone Weld.Part1 = v Clone.Parent = CurrentCamera--Hides it from everyone else ClonedArms[i] = Clone end Character.Humanoid.Died:connect(function() wait() for Index,Parts in pairs (ClonedArms)do print(Parts.Name) Parts:Destroy() table.remove(ClonedArms,Index) Parts:BreakJoints() end end) end return ClonedArms end --------------------------------------------------------- MakeDisplayArms()
If you want to test it in place it's here.
It's so hard working with local scripts. qq
LocalScripts often run before the character has been created.
Change line 2 to:
Character = Player.Character or Player.CharacterAdded:wait()
If Player.Character is nil, like in your case, then it will wait until the CharacterAdded event fires. The CharacterAdded event returns the character object, so it sets Character to that new object.
Edit: Since the reply chain was getting too long, I'll reply with some code changes:
I tested this code in online mode and it seems to work. Let me know if you have any more questions.
Player = game.Players.LocalPlayer local Character = Player.Character if not Character or Character.Parent == nil then Character = Player.CharacterAdded:wait() end Player.CameraMode= Enum.CameraMode.LockFirstPerson function MakeDisplayArms() local CurrentCamera = game.Workspace.CurrentCamera local PlayerArms = { Character:WaitForChild("Right Arm"), Character:WaitForChild("Left Arm") } local ClonedArms = {} for i,v in pairs (PlayerArms) do wait() local Clone = v:Clone() Clone.Name = "Cloned_"..v.Name --Renames it print(Clone.Name .. " created") Clone.CanCollide = true local Weld = Instance.new("Weld",Clone) Weld.Part0 = Clone Weld.Part1 = v Clone.Parent = CurrentCamera--Hides it from everyone else ClonedArms[i] = Clone end Character:WaitForChild("Humanoid").Died:connect(function() wait() print("Died") CurrentCamera:ClearAllChildren() end) end MakeDisplayArms()