Can't get a variable or a table from a local script

The module should be normal since it has the local “Profiles” as a table , but my script can’t get it ?

local Datastore =require(game.ServerScriptService["Data / Important"].Datastore) 

local event = game.ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("Gameloaded")
local Players = game:GetService("Players")



event.OnServerEvent:Connect(function(Player)
	local profilesStore = Datastore["Profiles"]
	local profile = profilesStore[Player]
	if profile ~= nil then
	

	
		if Player:IsDescendantOf(Players) == true then
			if profile.Data.Tutorial == false then
				
			--do something
		
			
			
		end
	
	
		
	end
	
		
	
	end
	end)

As I’ve stated in your duplicate post, the problem isn’t with this script alone. What is the full error, complete with stack trace and line numbers, and what is the code in the ModuleScript?

1 Like

I was wondering why do I need to Return exactly one value from a module, I have seen that for others they can require a Module without needing return, on their module that they are requiring,

Also sorry , I Figured that I would ask about that first

I don’t know who can make a module that doesn’t return anything, that isn’t really how they’re supposed to work (even if it does work). Though it might be possible to return nil, I’m not sure why someone would

I am using ProfileService ( a somewhat popular module for datastore ) , but when I looked at the setup of it and basic usage I was supposed to make a module script but the script I was advised to use doesn’t use return.
https://madstudioroblox.github.io/ProfileService/tutorial/basic_usage/
So could you maybe explain on how that works?, if you may

1 Like

You can’t get anything that is either on ServerScriptService or ServerStorage as those are only visible and accesible for the Game-server.

The solution for this is moving ProfileService to ReplicatedStorage, Create a separate module for managing data (Can be a wrapper for ProfileService, It should also be on ReplicatedStorage) and then require the module.

Here’s what the wrapper would look like. You are also free to put it inside folders for better organization/management. (For the sake of example, this is just a prototype)

-- Assuming it is directly parented to ReplicatedStorage...
-- You can also add more functions for Creating, Managing, etc.
local ProfileService = require(script.Parent.ProfileService)
local ProfileManager = {}
local ProfileCache = {}

function ProfileManager:GetProfile(ProfileName)
    return ProfileCache[ProfileName]
end

function ProfileManager:GetProfileData(ProfileName)
    local Profile = self:GetProfile(ProfileName)
    local Data = Profile and Profile.Data
    return Data
end

return ProfileManager
1 Like

I apologize for being somewhat limited here, I’m on my phone since I’m sick with COVID and can’t really get up to use my computer. I took a look at the example code they provided in the link you sent. That’s just a regular Script and they don’t use Datastore.Profiles anywhere. I assume it doesn’t exist because of the error you are getting. Try their example code, just copy it directly. It looks like it’s fully functional as-is and you only need to alter the data template at the top and the ‘DoSomething’ functions.

1 Like

Yeah its fine. I was wondering that it could maybe be a normal script, but I saw some video where they used similar code on a module and called the module , but maybe things have changed since those videos came out. Thanks for your Help, I will try to figure it out when I get back to studio.

1 Like

I forgot to return a specific table in the module , Apologizes!

2 Likes