local datastore2 = replicatedstorage.Events:WaitForChild("Communication"):InvokeServer()
Your supposed to load data from the server, this won’t work on the client, even if it’s in replicated storage.
EDIT: If you look deep into the code of Datastore2 You will see that it uses regular datastore, but in a very interesting way.
What is wrong with it???
its a gui template created in startergui, how would i do this in a serverscript?
Can you send the full code (Client).
local replicatedstorage = game:GetService("ReplicatedStorage")
local armormodule = require(game.ReplicatedStorage:WaitForChild("ArmorHandler"))
local datastore2 = replicatedstorage.Events:WaitForChild("Communication"):InvokeServer()
replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)
local template = script.Parent.MainGui.InventoryHolder.Inventory.Templates.Template
local newTemplate = template:Clone()
newTemplate.Parent = script.Parent.MainGui.InventoryHolder.Inventory.Duplicates
local newArmor = armormodule.chooseRandom():Clone()
local camera = Instance.new("Camera")
local armorname = newArmor.Name
local template2 = script.Parent.MainGui.Reward.Template
local newTemplate2 = template2:Clone()
newTemplate2.Parent = script.Parent.MainGui.Reward
camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
camera.Parent = newTemplate2.ViewportFrame
newArmor.Parent = newTemplate2.ViewportFrame
newTemplate2.ViewportFrame.CurrentCamera = camera
script.Parent.MainGui.Reward.Visible = true
newTemplate2.Visible = true
wait(2)
script.Parent.MainGui.Reward.Visible = false
newTemplate2.Visible = false
newTemplate.Visible = true
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
local inventorystore = datastore2("Inventory", player)
inventorystore:OnUpdate(function(currentTable)
return currentTable
end)
end)
aren’t i using a local script?
You cannot update on the client, you must use a remote event to fire the client with the new data, the remote function seems to have no use.
What you need to do is, fire a remote event on the client telling the server to save the data through datastore2, and then make it so the server will save the data when the remote event gets fired.
so i would fire a remote event, and what would the parameter be? (sorry im not really good with using remotes or functions)
Just fire the remote event, and make the server save the player’s inventory. There is one argument you will need, and this will be the player argument. However, this argument is already added in by roblox so you don’t need to add it in. The player argument on the server is the very first argument:
remoteEvent.OnServerEvent:Connect(function(player, ...) -- Player is the first argument
end)
Basic Map Out of Events:
- Datastore Value Updates(On the Server) > Remote Event is Fired to the Client(s) > RemoteEvent is Received (OnClientEvent) > Update Code is executed with the parameter of the new value.
would i add under the event?
local inventorystore = datastore2("Inventory", player)
inventorystore:OnUpdate(function(currentTable)
return currentTable
local datastore2 = require(PATH_TO_DATA_STORE_2_MODULE)
remoteEvent.OnServerEvent:Connect(function(player)
local inventorystore = datastore2("Inventory", player)
inventorystore:Set(inventory)
end)
for my case should inventory be changed to currentTable?
Forgot to mention. The inventory
variable should be a serversided variable. The client should never send anything to the server, and the server should never get any info from the client without validating it first.
inventorystore:OnUpdate(function(currentTable)
And shouldn’t i use onupdate?
Does this remote event get fired every time the client’s inventory updates?
on the datahandler :
InventoryStore:OnUpdate(function(decodedData)
inventoryString.Value = HttpService:JSONEncode(decodedData)
end)
Or maybe decodedData