Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- players.PlayerAdded:Connect(function(player) -- when a player joins this all
- local character = player.Character or player.CharacterAdded:Wait()
- local creditStore = DataStore2("credit", player) -- setting up money save
- local toolsStore = DataStore2("Tools", player) -- setting up tool save
- local function updateClientCredits(amount) -- updates credits
- replicatedstorage.ClientCreditUpdate:FireClient(player, amount) -- updates the credit UI
- end
- updateClientCredits(creditStore:Get(defaultCreditAmount)) -- if theres no data for credits it will set to the default amount
- creditStore:OnUpdate(updateClientCredits) -- whenever the credit number is changed it updates
- local function CharacterAdded(char)
- local toolsStore = DataStore2("Tools", player)
- local Backpack = player.Backpack
- local toolData = nil
- local Ready = false
- if Ready == false then
- Ready = true
- toolData = toolsStore:Get(nil)
- if toolData then
- toolGive(player, toolData) -- fires the function to actually give the tools
- Edit(player, toolData)
- end
- end
- --[[ this code doesn't belong here, you're calling the function from itself
- CharacterAdded(character)
- player.CharacterAdded:Connect(CharacterAdded)
- --]]
- local count = 0
- local function Adjust() -- adds stuff to the list of tools that save
- local list = {}
- local toolsStore = DataStore2("Tools", player)
- local equippedTool = char:FindFirstChildOfClass("Tool")
- if equippedTool then
- table.insert(list, equippedTool.Name)
- toolsStore:Set(list)
- end
- local Tools = Backpack:GetChildren()
- for i = 1, #Tools do
- table.insert(list, Tools[i].Name)
- toolsStore:Set(list)
- end
- if count ~= #list then
- Edit(player, toolData)
- count = #list
- end
- end
- Backpack.ChildAdded:connect(Adjust)
- Backpack.ChildRemoved:connect(Adjust)
- char.ChildAdded:connect(function(child) -- Whenever something is added it will add stuff to the list of saving
- if child.ClassName == "Tool" then
- Adjust()
- end
- end)
- char.ChildRemoved:connect(function(child)-- Whenever something is added it will remove stuff to the list of saving
- if child.ClassName == "Tool" then
- Adjust()
- end
- end)
- end -- char added function end
- -- code belongs here since it's in the playeradded block
- CharacterAdded(character)
- player.CharacterAdded:Connect(CharacterAdded)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement