Why is LocalPlayer a nil value?
So yeah, I was trying to make a backpack storage Gui. Obviously, I tried to put the two values (BackpackStorageUsed, BackpackStorage) into a folder inside the player because everyone would have different used amount of storage. So, I tried it and in the Output it said:
09:04:08.890 - ServerScriptService.Script:15: attempt to index local 'player' (a nil value)
Can anyone help? I have two scripts; one ClickDetector script so that when I click it, the BackpackStorageUsed value will go up by one, and the other is to keep updating the Gui and to create all the values when the player joins:
01 | local Backpack = Instance.new( "Folder" ) |
02 | local player = game.Players.LocalPlayer |
03 | local BackpackStorageUsed = Instance.new( "IntValue" , Backpack) |
04 | local BackpackStorage = Instance.new( "IntValue" , Backpack) |
05 | local BackpackIndicator = game.StarterGui.BackpackGui.BackpackIndicator |
07 | Backpack.Name = "Backpack" |
08 | Backpack.Parent = player |
09 | BackpackStorageUsed.Name = "BackpackStorageUsed" |
10 | BackpackStorage.Name = "BackpackStorage" |
11 | BackpackStorage.Value = 10 |
12 | BackpackStorageUsed.Value = 0 |
15 | script.Parent.Parent.StarterGui.BackpackGui.BackpackIndicator.Text = "Bag: " ..player.Backpack:FindFirstChild( "BackpackStorageUsed" ).Value.. "/" ..player.Backpack:FindFirstChild( "BackpackStorage" ).Value |
Here's the other one:
01 | local GiantBone = game.Workspace.GiantBone |
02 | local BackpackStorageUsed = game.Players.LocalPlayer.Backpack.BackpackStorageUsed |
03 | local BackpackStorage = game.StarterGui.BackpackGui.BackpackIndicator.BackpackStorage |
05 | GiantBone.ClickDetector.MouseClick:Connect( function () |
06 | BackpackStorageUsed.Value = BackpackStorageUsed.Value + 1 |
08 | if BackpackStorageUsed.Value = = BackpackStorage.Value then |
09 | GiantBone.ClickDetector.MaxActivationDistance = 0 |
10 | if BackpackStorageUsed.Value = = BackpackStorageUsed.Value > BackpackStorage.Value then |
11 | GiantBone.ClickDetector.MaxActivationDistance = 32 |