Infinite yield problem on datastore2

Im not sure why this is happening can someone help me?

local datastore2 = require(game.ServerStorage:WaitForChild("DataStore2"))

Heres full script if needed

local replicatedstorage = game:GetService("ReplicatedStorage")
local armormodule = require(game.ReplicatedStorage:WaitForChild("ArmorHandler"))


replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)
	local template = script.Parent.MainGui.Inventory.Templates.Template
	local datastore2 = require(game.ServerStorage:WaitForChild("DataStore2"))
	local inventoryStore = datastore2("Inventory", player)
	local newTemplate = template:Clone()
	local armorname = armor.Name
	newTemplate.Parent =  script.Parent.MainGui.Inventory.Duplicates
	newTemplate.Visible = true

	local newArmor = armormodule.chooseRandom():Clone()

	local camera = Instance.new("Camera")
	camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
	camera.Parent = newTemplate.ViewportFrame
	newArmor.Parent = newTemplate.ViewportFrame

	newTemplate.ViewportFrame.CurrentCamera = camera
	
end)
1 Like

What is this scipt for? A armor game?

yes?

How did I even guess. O_O. So can you show me the output?

Can you show us your ServerStorage?

The client can’t access the contents of ServerStorage

1 Like

Screen Shot 2021-03-13 at 3.56.01 PM

but if i didn’t do serverstorage then the datastore2 script will break. I tried putting it in replicatedstorage but it said userid is not a valid member of armor

The client cannot access ServerStorage, only the Server. That is the issue.

Try using remote events/remote functions for the server to handle it

Can you change your local script to a normal script?

im already using a remote event though?

No, I mean like another remote event for another server script to detect it

what @TheDCraft said

You can send over the inventory data from the server to the client + where is the InventoryStore being used in this script?

1 Like

the inventory stored was set up in Screen Shot 2021-03-13 at 4.00.01 PM

can you show me an example?

replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor, data)
       -- Everything when the client recives this event | added Data to the parameter
end)

Essentially the data you are sending over is the players data, that way you wouldn’t need to access it from client, whenever you are working with data make sure its always on the server.

1 Like
-- client
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteFunction")
local inventoryData = remote:InvokeServer() -- get the inventory data
-- server
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteFunction") -- the remote function
local dataStore2 = require(ModuleScript) -- the data store 2 module script

remote.OnServerInvoke = function(player)
   return dataStore2("Inventory", player) -- return the player's inventory data to the client
end

The client asks the server to get the player’s inventory data and return it to the client.

Also, I don’t use DataStore2 so I might mess up some things

Can you please explain to me what a remote function does because i can’t tell the difference between events and functions