Local script can't get datastore2 module in serverstorage

So im trying to get the datastore2 module script in serverstorage but can’t so i move it to replicatedstorage but it says this


So i am not sure what to do about this, is there a solution to this problem?

The client cannot access serverstorage

2 Likes

yes, i found that out so im not sure what to do about it though

Can we see your hierarchy? abc

1 Like

Starting from boss script

You also cannot access DataStores in a LocalScript, so DataStore2 is probably completely useless to require on the client.

how would i be able to use this then?

replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)

Local Script cannot access the ServerStorage nor ServerScriptService as mentioned in other replys. If you wish to get data from your Datastore use RemoteFunctions to return data to the Local Script.

can you show me an example of a remote function in my case if thats ok?

Ok lets say you want to assign a specific RemoteFunction just to get data for example how much money a player has.

--Server

RemoteFunctionObject.OnServerInvoke = function(Player)
    --GetCodeDataHere
    return Data -- Returns Data
end

--Client

local Data = RemoteFunctionObject:InvokeServer()
print(Data) -- Will print what data was returned.

Edit: Make sure you Change “Data” to the variable of what you want to return or change it directly to the GetAsync and make sure you chance “RemoteFunctionObject” to where your Function is. E.g. game.ReplicatedStorage.GetMoneyData.OnServerInvoke....

1 Like

would the client look something like this?

local datastore2 = replicatedstorage.Events:WaitForChild("Communication"):InvokeServer()

Yes, thats precisely what it should look like.

and also like this?

event.OnServerInvoke = function(Player)
	require(game.ServerStorage:WaitForChild("DataStore2"))
end

Sorry im just want to make sure

local Datastore2 = require(game.ServerStorage:WaitForChild("DataStore2")) -- Dontrequire something everytime it invokes.
event.OnServerInvoke = function(Player)
	local Data = Datastore2(--[[KeyName etc]])
    return Data
end

do i need a key name? or can i just put datastore2 by itself?

Have you actually read the Datastore2 Documentation? Assuming your using this Datastore2

Screen Shot 2021-03-16 at 6.48.01 PM

Can you send a screenshot of the code?

The whole thing or just line 3?

Just line 3 would help please.