Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datastore2 Not Saving Mob Drops?

Asked by
SWX253 2
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:

01if hit.Parent.Parent then --Defined via touched event
02                                local Player = hit.Parent.Parent
03                                if game.Players:GetPlayerFromCharacter(Player) then
04                                    local PlayerObj = game.Players:GetPlayerFromCharacter(Player)
05                                    print(PlayerObj)
06 
07                                    local goldDataStore = Datastore2("gold", PlayerObj)
08                                    local expDataStore = Datastore2("exp", PlayerObj)
09                                    local levelDataStore = Datastore2("level", PlayerObj)
10                                    if Player:FindFirstChild("Humanoid") then
11 
12                                        local Human = Player:FindFirstChild("Humanoid")
13                                        if Config.RestoreHealth == true then
14                                            Human.Health = Human.MaxHealth
15                                        end
16                                        goldDataStore:Increment(Config.AwardedGold)
17                                        expDataStore:Increment(Config.AwardedXP)
18                                        levelDataStore:Increment(Config.AwardedLvl)
19                                        print("Stats Awarded")

Here's the Datastore Handler:

01-- Datastore2 Declarations
02local Datastore2 = require(SSS.MainModule) --SSS is refers to ServerScriptService and Main Module is of Datastore2
03 
04local defaultGold = GameConfig.DefaultGold
05local defaultExp = GameConfig.DefaultExp
06local defaultLevel = GameConfig.DefaultLevel
07 
08Datastore2.Combine("Data", "gold", "exp", "level")
09 
10-- Create leaderstats
11game.Players.PlayerAdded:Connect(function(plr)
12    local goldDataStore = Datastore2("gold", plr)
13    local expDataStore = Datastore2("exp", plr)
14    local levelDataStore = Datastore2("level", plr)
15 
View all 46 lines...

What seems to be the issue?

Answer this question