UpdateEquip.UpdateWeapon = function(player, serial)
local equipStore = Datastore2("Equipped", player); local equipStoreData = equipStore:GetTable(Equip.EquippedTable)
local equipStoreData = {
["Weapon"] = serial,
}
equipStore:Set(equipStoreData)
equipStore:Save() -- Not sure if this is needed
end
So I know I am being dumb right now, but for some reason this doesn’t save the data? am I doing something wrong, I have read that :Set should set the new value, I read this document and looked on this forums and google searched, but for some reason my brain won’t function for some reason, any reason why this doesn’t work? There are no errors. So any help would be appreciated.
Yeah, I added some prints to make sure it got to the function as well. This is the code for it:
Event.OnServerEvent:Connect(function(player, item, animation, frame)
local char = player.Character or player.CharacterAdded:Wait()
local tool = item:Clone()
tool.Name = "EquippedWeapon"
tool.Parent = char
char.Animate.toolnone:WaitForChild("ToolNoneAnim").AnimationId = "http://www.roblox.com/asset/?id="..animation
frame.Parent = frame.Parent.Parent
frame:TweenPosition(UDim2.new(-1.015, 0, 0.771, 0),"Out","Quart",0.1) -- Side of the screen
for i, v in pairs(item.Stats:GetChildren()) do
if v.Name == "Serial" then
Update.UpdateWeapon(player, v.Value)
end
end
end)
This should work. You can’t assign a variable when calling a function like that.
UpdateEquip.UpdateWeapon = function(player, serial)
local equipStore = Datastore2("Equipped", player);
local equipStoreData = equipStore:GetTable(Equip.EquippedTable)
equipStoreData.Weapon = serial
equipStore:Set(equipStoreData)
equipStore:Save() -- Not sure if this is needed
end
Also, it might be better to save when the player leaves rather than each time they update their weapon. Otherwise, you might reach the limits of DataStore often and it’ll begin to error.
This is in a module script inside of my datastoreHandler which uses datastore2. Oh I think I just printed the default table twice and not the players table.
Datastore2.Combine("Inventory", "Armour", "Weapons","Stats","Potions","Equipped")
local function GetData(player)
local armourStore = Datastore2("Armour", player); local armourStoreData = armourStore:GetTable(Armour.ArmourTable)
local potionsStore = Datastore2("Potions", player); local potionsStoreData = potionsStore:GetTable(Potions.PotionTable)
local weaponsStore = Datastore2("Weapons", player); local weaponsStoreData = weaponsStore:GetTable(Weapons.WeaponsTable)
local statsStore = Datastore2("Stats", player); local statsStoreData = statsStore:GetTable(Stats.StatsTable)
local equipStore = Datastore2("Equipped", player); local equipStoreData = equipStore:GetTable(Equip.EquippedTable)
give.Give("Weapons", Weapons.WeaponsTable, player, Equip.EquippedTable)
give.Give("Armour", Armour.ArmourTable, player, Equip.EquippedTable)
give.Give("Potions", Potions.PotionTable, player, Equip.EquippedTable)
end
players.PlayerAdded:Connect(GetData)
UpdateEquip.UpdateWeapon = function(player, serial)
local equipStore = Datastore2("Equipped", player);
local equipStoreData = equipStore:GetTable(Equip.EquippedTable)
print(serial)
for i, v in pairs(Equip.EquippedTable) do
print(i..v)
end
equipStoreData.Weapon = serial
equipStore:Set(equipStoreData)
equipStore:Save() -- Not sure if this is needed
for _, c in pairs(Equip.EquippedTable) do
print(_..c)
end
end
This is what I did to check, but I’m not sure how to check the players value. Would it check the equipStore since that is assigned to the player.
give.Give = function(tool, tablearea, player, equiptable) -- Tool being weapon/armour/potions / Tablearea being Weapons.WeaponTable
for num, item in pairs(ReplicatedStorage[tool]:GetChildren()) do -- Checks all the weapons in the weapons folder
for serial, name in pairs(tablearea) do -- Checks table
if item.Name == name["Name"] and name["Quantity"] >= 1 then -- if they own it
if item.Stats.Serial.Value == serial then -- Checks to see if it's the correct serial
for ser, itm in pairs(equiptable) do
if serial == equiptable[tool] then
print("You made it here!")
local weap = item:Clone()
weap = player.Character
end
end
for i = 1,name["Quantity"] do
--print("We made it here")
adding.AddedEvent(item, tool, player)
end
end
end
end
end
end
This is the function, so I think I will have to do the players table instead of the template.