When requesting datastore, it loads a completely different one

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!
    When the player loads in, it loads the correct datastore

  2. What is the issue? Include screenshots / videos if possible!
    When I was testing in studio it loads the correct datastore and loads all the values but when I go into the actual game it loads a completely different datastore

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried defining the datastore and tried changing the scope and key but nothing has changed and still loads the other datastore

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

When I load into Studio is loads the players data correctly and has the exact values I set them as (“CharacterData”) but when I play on client it loads “CharacterData” as “PlayerData”

Also I am using Suphi Kaner’s Datastore module

-- Services
local RunService = game:GetService("RunService")
local TeleportService = game:GetService("TeleportService")

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")

-- Modules
local Inputs = require(ServerScriptService.Core.Modules.Inputs)
local Functions = require(ServerScriptService.Core.Modules.Functions)

local DataStoreModule = require(ServerStorage.Modules.DataStore)

local CharacterHandler = require(script.CharacterHandler)

-- High Priority Variables
local SlotInfo = {}

-- High Priority Functions
local function StateChanged(State, DataStore, Template)
	while DataStore.State == false do -- Keep trying to re-open if the state is closed
		if DataStore:Open(Template) ~= "Success" then 
			task.wait(6) 
		end
	end
end

local function OnPlayerAdded(Player : Player)
	local LoadingGui = ReplicatedStorage.Components.Gui.LoadingGui:Clone()
	LoadingGui.Parent = Player.PlayerGui
	
	local PlayerData = DataStoreModule.new("PlayerData", "Player_" .. Player.UserId)
	PlayerData.StateChanged:Connect(StateChanged)
	StateChanged(PlayerData.State, PlayerData,  require(script.DataTemplates.DataTemplate_Player))
	
	if PlayerData.Value.Banned == true then
		Player:Kick("You have been banned from this experience")
		return
	end
	
	if SlotInfo[Player.UserId] == nil then
		SlotInfo[Player.UserId] = {}
	end
	
	if RunService:IsStudio() then
		SlotInfo[Player.UserId]["Slot"] = "A"
	else
		PlayerData.ProcessQueue:Connect(function(ID, Values, Datastore)
			SlotInfo[Player.UserId]["Slot"] = Values[1]
			PlayerData:Remove(ID)
		end)
	end
	
	local CharacterData = DataStoreModule.new("PlayerData", "Player_" .. Player.UserId, SlotInfo[Player.UserId]["Slot"])
	CharacterData.StateChanged:Connect(StateChanged)
	StateChanged(CharacterData.State, CharacterData, require(script.DataTemplates.DataTemplate_Character))
	
	if CharacterData.Value.FirstName == "N/A" then
		local NameSelection = ReplicatedStorage.Components.Gui.NameSelection:Clone()
		NameSelection.Parent = Player.PlayerGui
	end
	
	Inputs.InputTable[Player] = {}
	
	Player.CharacterAdded:Connect(function(Character : Model)
		LoadingGui:Destroy()
		
		local Humanoid = Character:WaitForChild("Humanoid")

		Character:SetAttribute("Stunned", false)
		Character:SetAttribute("Attacking", false)
		Character:SetAttribute("Blocking", false)
		
		if CharacterData.Value.FirstName == "N/A" then -- If there name is "N/A" then wait until it's not then enter their name
			task.spawn(function()
				repeat 
					task.wait()
				until CharacterData.Value.FirstName ~= "N/A"
				Humanoid.DisplayName = tostring(CharacterData.Value.FirstName .. " " .. CharacterData.Value.LastName)
			end)
		else
			Humanoid.DisplayName = tostring(CharacterData.Value.FirstName .. " " .. CharacterData.Value.LastName)
		end
		
		CharacterHandler["LoadApperance"](Player, CharacterData.Value.LastName, false)
	end)
	Player:LoadCharacter()
end

local function OnPlayerRemoving(Player : Player)
	local PlayerData = DataStoreModule.find("PlayerData", "Player_" .. Player.UserId)
	local CharacterData = DataStoreModule.find("PlayerData", "Player_" .. Player.UserId, SlotInfo[Player.UserId]["Slot"])

	if PlayerData ~= nil then
		PlayerData:Destroy()
	end
	if CharacterData ~= nil then
		CharacterData:Destroy()
	end
end

Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
for _, Player in Players:GetPlayers() do
	task.spawn(OnPlayerAdded, Player)
end

ServerStorage.Functions.SlotTable.OnInvoke = function(Player : Player)
	task.wait()
	return SlotInfo[Player.UserId]["Slot"]
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like