Answered by
3 years ago Edited 3 years ago
You're trying to access Backpack and the Destroy function of something that doesn't exist, so basically nil.Backpack and nil:Destroy(). I'm guessing that this part is touching another part of itself, and "plr" gets set to nil in line 2 and line 14 because the part doesn't have a player associated with it.
Just do a simple check to make sure "plr" isn't nil before the rest of the code executes:
01 | script.Parent.Touched:Connect( function (Char) |
02 | local plr = game.Players:GetPlayerFromCharacter(Char.Parent) |
04 | local backpack = plr.Backpack |
05 | local sword = game.Lighting.Storage.ClassicSword:Clone() |
06 | local con = game.Lighting.Storage.HasPvP:Clone() |
07 | if not backpack:FindFirstChild( "HasPvP" ) then |
08 | sword.Parent = backpack |
you should probably also put the sword in ReplicatedStorage or ServerStorage because having models mixed up with postprocessing effects and all that will be an organization nightmare later on