The script doesn't work, I need help, will someone debug FOR me?

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Slot1Taken")
local DataStore2 = DataStoreService:GetDataStore("CurrentImage")
local DataStore3 = DataStoreService:GetDataStore("NumberAmount")

game.Players.PlayerAdded:connect(function(p)
    local register = DataStore:GetAsync("user_" .. p.UserId)
    if register then
		local slot1taken = p:WaitForChild("Slot1Taken")
		slot1taken.Value = DataStore:GetAsync(register)
	
		local slot1currentimage = p.PlayerGui.MenuGui.InventoryMain.InventoryFrame.InventoryBackground.ElementSlot1.ElementImage:WaitForChild("CurrentImage")
		slot1currentimage.Value = DataStore2:GetAsync(register)
	
		local slot1amount = p.PlayerGui.MenuGui.InventoryMain.InventoryFrame.InventoryBackground.ElementSlot1.ElementImage.Amount:WaitForChild("NumberAmount")
		slot1amount.Value = DataStore3:GetAsync(register)
        -- do stuff with that
    else
		local slot1taken = p:WaitForChild("Slot1Taken").Value
		local slot1amount = p.PlayerGui.MenuGui.InventoryMain.InventoryFrame.InventoryBackground.ElementSlot1.ElementImage.Amount:WaitForChild("NumberAmount").Value
		local slot1currentimage = p.PlayerGui.MenuGui.InventoryMain.InventoryFrame.InventoryBackground.ElementSlot1.ElementImage:WaitForChild("CurrentImage").Value
        local newRegister = DataStore:SetAsync("user_" .. p.UserId, slot1taken)
		local newRegister = DataStore:SetAsync("user_" .. p.UserId, slot1amount)
		local newRegister = DataStore:SetAsync("user_" .. p.UserId, slot1currentimage)
        --Rinse and repeat for other DataStores
    end
end)

--Keep the other things (but try and minimize the amount of times you use DataStore functions, there's a limit to how many you can use per minute
--For example, if you are using the players user ID, don't bother getting that from a datastore, just simply grab it from the script

Please debug for me :C

2 comments

0

The only thing you should do in PlayerAdded is a single GetAsync(). And you probably should not try to access PlayerGui this way.

0

Try using a local script and just doing p use game.StarterGui.LOLTHISGUI.Frame