I have a regular script located in my ServerScriptService and I have a auto-saving money script that goes with it so it can save my money. The auto-saver works fine but I just need to find out why my money currency is not adding when a player purchases or purchased a gamepass.
Gamepass Script:
local player = script.Parent.Parent
local leaderboard = player:WaitForChild("leaderstats")
local currency1 = leaderboard:WaitForChild("Money")
local id = 1289535025
game.Players.PlayerAdded:connect(function(player)
if game:GetService("GamePassService"):PlayerHasPass(player, id) then
print(player.Name .. " has the game pass!")
currency1.Value = currency1.Value + 500
else
print(player.Name .. " doesn't have the game pass...")
end
end)
Just in case: Auto-Saver script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Money")
game.Players.PlayerAdded:connect(function(player)
local key = "key-"..player.UserId
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue",folder)
currency1.Name = "Money"
local save = DataStore:GetAsync(key)
if save then
currency1.Value = save[1]
else
local load = {currency1.Value}
DataStore:SetAsync(key,load)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local key = "key-"..player.userId
local load = {player.leaderstats:FindFirstChild("Money").Value}
DataStore:SetAsync(key,load)
end)
Thanks!
