Greetings DevForum,
I have created a module script which works in conjunction with a serverscript to setup datastore2 values however I cannot figure out how I might do a fire server event to change the value of a particular table which is within the settings table setup.
--This is my server script
local DataStore2 = require(1936396537)
local Settings = require(game.ReplicatedStorage.Datastore2Values) --Must require the modulescript
game.Players.PlayerAdded:Connect(function(player) --Player added
for i,v in pairs(Settings) do
local datastore = DataStore2(i,player) --1 = the datastorename,player = the player
local where = v.Where --Where the datastore gets saved at
if v.Where ~= "Player" then
if player:findFirstChild(v.Where) then --if the folder is already created then
where = player[v.Where]
else
local folder = Instance.new("Folder",player)
folder.Name = v.Where
where=folder
end
end
if v.Where == "Player" then
where=player
end
--Value creation
local val = Instance.new(v.What,where)
val.Name = i --The name
val.Value = v.Value --How much I set it to
--Loading datastore2
if datastore:Get() ~= nil then --If datastore already exists
val.Value = datastore:Get() --loads in players data
end
--Saving
val.Changed:connect(function()
datastore:Set(val.Value)
end)
end
end)
--This is my module script
local Settings = {
["AttackValue"] = {
["Where"] = "Player",
["What"] = "IntValue",
["Value"] = 1000,
},
["DefenseValue"] = {
["Where"] = "Player",
["What"] = "IntValue",
["Value"] = 1000,
},
["KiValue"] = {
["Where"] = "Player",
["What"] = "IntValue",
["Value"] = 1000,
},
["ZenkaiValue"] = {
["Where"] = "Player",
["What"] = "IntValue",
["Value"] = 0,
},
}
return Settings
--game.ReplicatedStorage.AttackIncrement.OnServerEvent:Connect(function(player, value)
--local AttackDataStore = DataStore2("AttackDataStore", player)
--AttackDataStore:Increment(Value)
--I don't think incrementing by datastore would work