This script would work with leaderstats. However we switched to a datastore in order to save data (obviously). However, with the data store, it doesnt work. Instead the script shows this error:
attempt to index a nil value (LINE 4 & 15)
If you find a fix for this please help me. Been trying for 2 hours. Heres some information:
CurrentBackpack is a string value that is in the player. (EXAMPLE: game.Players.LocalPlayer:FindFirstChild("CurrentBackpack"))
CurrentBP.Value is just the string value of the Current Backpack. Examples are: SmallBackpack, MediumBackpack, Etc). In here it gets for example SmallBackpack and finds it in ReplicatedStorage to clone into the player
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(character)
local CurrentBP = plr:WaitForChild("CurrentBackpack")
local FirstBp = game.ReplicatedStorage.GameObjects.Backpacks:FindFirstChild(CurrentBP.Value):Clone()
print(FirstBp)
FirstBp.Parent = character
FirstBp.Name = "Backpack"
plr:WaitForChild("CurrentBackpack").Changed:connect(function(value)
print(value)
local NewBackpack = game.ReplicatedStorage.GameObjects.Backpacks:FindFirstChild(plr.CurrentBackpack.Value):Clone()
character:FindFirstChild("Backpack"):Destroy()
NewBackpack.Parent = character
NewBackpack.Name = "Backpack"
end)
end)
end)

2 comments
Try to use :WaitForChild()
Is GameObjects a child of ReplicatedStorage? Is Backpacks a child of GameObjects?