You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Im trying to use DataStore2 to save my Data (Wins, Level and Exp).
What is the issue? Include screenshots / videos if possible!
When I go into Play, I get this error: ServerScriptService.DataStore2:479: DataStore2() API call expected {string dataStoreName, Instance player}, got {table, Instance}
Not sure where it’s getting a table instead of a string in the script.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried finding solutions, but didn’t find any.
Script inside of ServerScriptService
local players = game:GetService("Players")
local DataStore2 = require(game.ServerScriptService.DataStore2)
DataStore2:Combine("Data", "wins")
DataStore2:Combine("Data", "level")
DataStore2:Combine("Data", "exp")
players.PlayerAdded:Connect(function(player)
local winsStore = DataStore2("wins", player)
local levelStore = DataStore2("level", player)
local expStore = DataStore2("exp", player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
winsStore:Get(0)
Wins.Parent = leaderstats
local Level = Instance.new("IntValue")
Level.Name = "Level"
levelStore:Get(1)
Level.Parent = leaderstats
local statsfolder = Instance.new("Folder")
statsfolder.Name = "Stats"
statsfolder.Parent = player
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
expStore:Get(0)
Exp.Parent = statsfolder
winsStore:OnUpdate(function(newValue)
Wins.Value = newValue
end)
levelStore:OnUpdate(function(newValue)
Level.Value = newValue
end)
expStore:OnUpdate(function(newValue)
Exp.Value = newValue
end)
Exp.Changed:Connect(function()
if Exp.Value >= Level.Value * 50 then
levelStore:Increment(1)
expStore:Set(Exp.Value - Level.Value * 50)
end
end)
end)
This is my first time using DataStore2, so it might just me being dumb lol
I see what you are doing wrong. DataStore2 function expects a string for the data store name, but you are passing a table instead.
local players = game:GetService("Players")
local DataStore2 = require(game.ServerScriptService.DataStore2)
local winsDataStore = "wins"
local levelDataStore = "level"
local expDataStore = "exp"
players.PlayerAdded:Connect(function(player)
local winsStore = DataStore2(winsDataStore, player)
local levelStore = DataStore2(levelDataStore, player)
local expStore = DataStore2(expDataStore, player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = winsStore:Get(0) -- Retrieve the value and set it initially
Wins.Parent = leaderstats
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Value = levelStore:Get(1) -- Retrieve the value and set it initially
Level.Parent = leaderstats
local statsfolder = Instance.new("Folder")
statsfolder.Name = "Stats"
statsfolder.Parent = player
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
Exp.Value = expStore:Get(0) -- Retrieve the value and set it initially
Exp.Parent = statsfolder
winsStore:OnUpdate(function(newValue)
Wins.Value = newValue
end)
levelStore:OnUpdate(function(newValue)
Level.Value = newValue
end)
expStore:OnUpdate(function(newValue)
Exp.Value = newValue
end)
Exp.Changed:Connect(function()
if Exp.Value >= Level.Value * 50 then
levelStore:Increment(1)
expStore:Set(Exp.Value - Level.Value * 50)
end
end)
end)