#Gamepass not working
55 messages · Page 1 of 1 (latest)
local GAMEPASS_ID = 848448753 -- Replace with your actual gamepass ID
local dollars = game.Players.LocalPlayer.leaderstats.Dollars
local function onGamepassPurchase(player, gamepassId)
if gamepassId == GAMEPASS_ID then
local playerData = game:GetService("DataStoreService"):GetDataStore("PlayerData")
local success, err = pcall(function()
local playerKey = "Player_".. player.UserId
local dollars = playerData:GetAsync(playerKey)
dollars.Value = dollars.Value + 500
playerData:SetAsync(playerKey, dollars)
end)
if not success then
warn("Error saving player data:", err)
end
end
end
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(onGamepassPurchase)
1 - On localscript if you change values it wouldn't be replicated to the server
2 - In localscripts DataStores cannot be used
3 - Due to the change is on the localscript and the server cannot see it the server cannot save it
4 - Only server can save to DataStore
mm so i js put local in a regular script didny i
no
btw when i play this is the leaderstats
so how do i fix it
you kind of have to change a bunch of the script
mm
you need to initialize players on playerAdded
chatgpt failed me fr
k
and on playerRemoved you need to save their data
** You are now Level 39! **
W
@pulsar parrot how should i do this
** You are now Level 4! **
w
on the playeradded event, load the data with :GetAsync do all the defaults and stuff and load it onto the leaderstats
i dont see a playeradded event though
Players.PlayerAdded
2 sec google search couldve answered faster than me lol
youre telling me to make one?
huh?
its the playeradded event of the Players service
it fires when a player joins
wdym
game.Players.PlayerAdded
js :Connect it to a function
yes i dont see the game.Players.PlayerAdded
ion know where you got that
is it in my script or am i js trippin balls rn
wth dym
show
its literally just
game.Players.PlayerAdded:Connect(function(playerWhoJoined)
end)
do you want me to add that to the code?
im so confused
You should learn to script properly first...
wdym
connect the playeradded event