When I did this it gave the error code of, attempt to index number with 'fire'
local DataStore = game:GetService("DataStoreService")
local mydatastore = DataStore:GetDataStore("mydatastore")-- making a datastore under the name my datastore
game.Players.PlayerAdded:Connect(function(player)
local ben = Instance.new ("Folder")
ben.Name = "ben"
ben.Parent = player
local fire = Instance.new ("IntValue")
fire.Name = "fire"
fire.Parent = ben
local water = Instance.new("IntValue")
water.Name = "water"
water.Parent = ben
local earth = Instance.new("IntValue")
earth.Name = "earth"
earth.Parent = ben
local air = Instance.new("IntValue")
air.Name = "air"
air.Parent = ben
local data -- this defines what data is we cant do it in the mid cuz its unknown global
local playeruserid = "player"..player.UserId
local success, errormessage = pcall(function() -- this finds out if the player has played the game before
data = mydatastore:GetAsync(playeruserid) -- this will sync the data to what we have in the data store
end)
if success then
fire.Value = data.fire
water.Value = data.water
earth.Value = data.earth
air.Value = data.air
--set our data = to the current fire
end
end)
game.Players.PlayerRemoving:Connect(function(player) -- if the player leaves this fires
local playeruserid = "player"..player.UserId
local data = {
fire = player.ben.fire.Value;
water = player.ben.water.Value;
earth = player.ben.earth.Value;
air = player.ben.air.Value;
}
local success, errormessage = pcall(function()
mydatastore:SetAsync(playeruserid, data) -- funtion that sets the async
end)
if success then
print("Datasuccesfuly saved")
else
print("There was an error")
warn (errormessage)
end
end)

2 comments
Which line is erroring?
Which ever line is listed first under if success then, in this case fire