✓ Accepted answer
To do what you're trying to accomplish, we need to set up a DataStore, which we will fill with the users that have bought the GamePass.
First, lets define the DataStore key that we'll be using, and the gamepass required.
local ds = game:GetService("DataStoreService"):GetDataStore("IncreasedGold")
local passId = 198893078
Now, lets have whenever a player joins.. we check if they have the gamepass. And if they have the gamepass, we check if they have data stored already. If they have data stored already it would mean that they've already been awarded the gold because if they don't have data, but have the gamepass.. then we're going to set up data(:
game.Players.PlayerAdded:connect(function(plr)
wait(1)
local key = tostring(plr.userId).."_Bought"
local data = ds:GetAsync(key)
local stats = plr.leaderstats.Gold
if data == nil then
if game:GetService("GamePassService"):PlayerHasPass(plr,passId) then
ds:SetAsync(key,true)
stats.Value = stats.Value + 50000
end
end
end)
So, lets put this whole script together. It should look like this:
local ds = game:GetService("DataStoreService"):GetDataStore("IncreasedGold")
local passId = 198893078
game.Players.PlayerAdded:connect(function(plr)
wait(1)
local key = tostring(plr.userId).."_Bought"
local data = ds:GetAsync(key)
local stats = plr.leaderstats.Gold
if data == nil then
if game:GetService("GamePassService"):PlayerHasPass(plr,passId) then
ds:SetAsync(key,true)
stats.Value = stats.Value + 50000
end
end
end)
I also suggest maybe adding a checking with a CharacterAdded Event, so that the player doesn't have to rejoin upon buyig the gamepass.
If you have any other questions feel free to comment on my answer or PM me on the site(:
1 comment
Please help!