Datastore2 Not Saving Mob Drops?
Asked by
4 years ago Edited 4 years ago
I'm working on an rpg mob's drop system. I've opted for Datastore2. The data (xp, gold, levels) doesn't seem to be saving though. I always get this error on levelDataStore:Increment(Config.AwardedLvl): ServerScriptService.MainModule:253: attempt to perform arithmetic (add) on function and number.
Here's the stat award script:
01 | if hit.Parent.Parent then |
02 | local Player = hit.Parent.Parent |
03 | if game.Players:GetPlayerFromCharacter(Player) then |
04 | local PlayerObj = game.Players:GetPlayerFromCharacter(Player) |
07 | local goldDataStore = Datastore 2 ( "gold" , PlayerObj) |
08 | local expDataStore = Datastore 2 ( "exp" , PlayerObj) |
09 | local levelDataStore = Datastore 2 ( "level" , PlayerObj) |
10 | if Player:FindFirstChild( "Humanoid" ) then |
12 | local Human = Player:FindFirstChild( "Humanoid" ) |
13 | if Config.RestoreHealth = = true then |
14 | Human.Health = Human.MaxHealth |
16 | goldDataStore:Increment(Config.AwardedGold) |
17 | expDataStore:Increment(Config.AwardedXP) |
18 | levelDataStore:Increment(Config.AwardedLvl) |
19 | print ( "Stats Awarded" ) |
Here's the Datastore Handler:
02 | local Datastore 2 = require(SSS.MainModule) |
04 | local defaultGold = GameConfig.DefaultGold |
05 | local defaultExp = GameConfig.DefaultExp |
06 | local defaultLevel = GameConfig.DefaultLevel |
08 | Datastore 2. Combine( "Data" , "gold" , "exp" , "level" ) |
11 | game.Players.PlayerAdded:Connect( function (plr) |
12 | local goldDataStore = Datastore 2 ( "gold" , plr) |
13 | local expDataStore = Datastore 2 ( "exp" , plr) |
14 | local levelDataStore = Datastore 2 ( "level" , plr) |
16 | local leaderstats = Instance.new( "Folder" ) |
17 | leaderstats.Name = "leaderstats" |
18 | leaderstats.Parent = plr |
21 | local Gold = Instance.new( "IntValue" , leaderstats) |
23 | local Exp = Instance.new( "IntValue" , leaderstats) |
25 | local Level = Instance.new( "IntValue" , leaderstats) |
30 | local function goldUpdate(updatedValue) |
31 | Gold.Value = goldDataStore:Get(updatedValue) |
33 | local function expUpdate(updatedValue) |
34 | Exp.Value = expDataStore:Get(updatedValue) |
36 | local function levelUpdate(updatedValue) |
37 | Level.Value = levelDataStore:Get(updatedValue) |
40 | goldUpdate(defaultGold) |
41 | goldDataStore:OnUpdate(goldUpdate) |
43 | expDataStore:OnUpdate(expUpdate) |
44 | levelUpdate(levelUpdate) |
45 | levelDataStore:OnUpdate(levelUpdate) |
What seems to be the issue?