#Gamepass not working

55 messages · Page 1 of 1 (latest)

rose flame
#

here is the script

#
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)
jade wing
#

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

rose flame
rose flame
#

btw when i play this is the leaderstats

rose flame
pulsar parrot
#

you kind of have to change a bunch of the script

rose flame
#

mm

pulsar parrot
#

you need to initialize players on playerAdded

rose flame
#

chatgpt failed me fr

pulsar parrot
#

so loading their data etc

#

ew chatgtp

#

dont use it for scripting

#

ever

rose flame
#

k

pulsar parrot
#

and on playerRemoved you need to save their data

deep harnessBOT
#

studio** You are now Level 39! **studio

pulsar parrot
#

W

rose flame
#

lol

#

wait

#

so im new to scripting

#

so uh

rose flame
deep harnessBOT
#

studio** You are now Level 4! **studio

rose flame
#

w

pulsar parrot
rose flame
pulsar parrot
#

2 sec google search couldve answered faster than me lol

rose flame
pulsar parrot
#

its the playeradded event of the Players service

#

it fires when a player joins

rose flame
#

OHHHH

#

bro what

#

im confused bro ion see no playeradded event

pulsar parrot
#

game.Players.PlayerAdded

#

js :Connect it to a function

rose flame
#

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

pulsar parrot
#

wth dym

#

show

#

its literally just

#

game.Players.PlayerAdded:Connect(function(playerWhoJoined)

end)

rose flame
#

im so confused

pulsar parrot
#

You should learn to script properly first...

rose flame
#

well

#

ik how to script

#

i js have no idea wtf you are talkin ab

pulsar parrot
#

connect the playeradded event