Am I doing this right?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Alright, so I have a local script that when you click the button it fires the name of the button the player clicked to the server, then assigns that as their save slot key to DataStore.
  2. What is the issue? Include screenshots / videos if possible!
    Should I use :GetAsync() only on the .OnServerEvent or when the player joins?
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried figuring out ways to set the parameter as a variable to use throughout the script.
RegisterSlot.OnServerEvent:Connect(function(localPlayer, SlotName)
	local SlotKey = localPlayer.Name.. " - "..SlotName
	
	if localPlayer then
		localPlayer:SetAttribute("Slot", SlotName)
		localPlayer:SetAttribute("Key", SlotKey)
	end
	
	local success, errormessage = pcall(function()
		local Data = SaveSlots:GetAsync(SlotKey)
		
		SaveSlots:GetAsync(SlotKey)
	end)
	
	if success then
		print("Successfully got slot!")
	else
		warn(errormessage)
	end
end)

I am awaiting responses. Help is appreciated.

If you allow the player to select different slots, then it’s best to do in the event. Note that I would advice coding in a debounce so that player’s can’t spam the event.

Also, within your code, you are retrieving the data (twice) but aren’t doing anything with it. Make sure to store it outside of the pcall scope.

1 Like

Yep. I did it in the event. Now how do I make the text save when they leave? I was going to index a value in the data, but I left it there.

Could I checking if the index in the data is there and then send it to the client to update the text?

Edit: I’m awaiting a response.

Alright, so I did a lot of trial and error and it finally worked.

I had to do a lot of calculations in order to figure things out.

game.Players.PlayerAdded:Connect(function(Player) -- When the player enters the game.
	local slotData
	local attributeData
	
	local SlotFolder = Instance.new("Folder")
	SlotFolder.Name = "SlotFolder"
	SlotFolder.Parent = Player
	
	local SlotStage = Instance.new("IntValue")
	SlotStage.Name = "SlotStage"
	SlotStage.Value = 0
	
	SlotStage.Parent = SlotFolder
	
	local SlotAttributeKey = "-slotattribute"
	
	local success, errormessage = pcall(function()
		attributeData = SlotAttributes:GetAsync(SlotAttributeKey)
		
		if attributeData then -- We have to check if the attributes are there otherwise we can't access the key!
			print("Number of indexes: "..#attributeData)
			
			Player:SetAttribute("Slot", attributeData[1])
			Player:SetAttribute("Key", attributeData[2])
			slotData = SaveSlots:GetAsync(Player:GetAttribute("Key"))
			
			SetSlotData:FireClient(Player, slotData, attributeData)
		end
	end)
end)

Thank you @PoppyandNeivaarecute :+1:

If you have any suggestions on the code or more convenient ways to script some parts, then please let me know.

Edit: It works, but you can’t activate multiple save slots. Once you activate another, it overwrites.