would the client look something like this?
local datastore2 = replicatedstorage.Events:WaitForChild("Communication"):InvokeServer()
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?
Can you send a screenshot of the code?
The whole thing or just line 3?
Just line 3 would help please.
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.