I'm trying to create a script that rewards the player 100 points for killing other players. The script works but since I'm using DataStore2 you're supposed to update their saved data instead of updating their leaderstats. (Or only the leaderstat will update but it won't be saved) I don't understand how to do this though because this is my first time trying to use DataStore2
Code:
local DataStore2 = require(game.ServerScriptService.StatsDataStore2:WaitForChild("MainModule"))
local Humanoid = script.Parent.Humanoid
function dead()
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag ~= nil then
local Leaderstats = tag.Value:findFirstChild("PlayerStats")
if Leaderstats ~= nil then
Leaderstats.Points.Value = Leaderstats.Points.Value + 100
--[[local PointsStore = DataStore2("Points", tag)
PointsStore:Increment(100) <-- My attempt at trying to update the value of their saved data didn't work ]]
wait(0.1)
script:Destroy()
end
end
end
end
Humanoid.Died:connect(dead)
Extra Info: This script is placed in StarterCharacter (Not sure if that's relevant or not)
