Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making PointsGiver if playerHasPass, won't work, why?

I'm making a point giver so if the player has a gamepass it gives them a certain amount of points, but it seems my code won't work!

local DiamondDollors = game.Players.LocalPlayer.leaderstats.DiamondDollors 
local Amount = 20000


local passId = 5888493 
local marketplaceService = game:GetService("MarketplaceService")

marketplaceService.PromptPurchaseFinished:connect(function(player,assetId,isPurchased)
    if isPurchased then
        if assetId == passId then
            DiamondDollors.Value = DiamondDollors.Value + Amount
        end
    end
end)

I don't understand why the script won't work, and I've tried researching it, and there's no errors or anything. So, I've turned to you guys! Any help or answers are very much appreciated!

5 comments

0

im not really sure but i think this needs to be script not localscript and you can't use game.Players.LocalPlayer

0

This is true, ServerScripts can’t reference game.Players.LocalPlayer because it doesn’t have one

0

Not due to FE. But because the server has no player of its own.

0

tell a parent to get the local child and you see what happens

0

Thanks for all of your help guys! The script is inside a ServerScript, but calls local functions, does this cause it to break? Plus, calling upon the parent for child didn't seem to work!

1 answer

✓ Accepted answer

The problem with your code is that you are referencing game.Players.LocalPlayer from a Script on the server.

As the script is in ServerScriptService it will run on Roblox's servers and not the player's computer, therefore game.Players.LocalPlayer does not exist.

in order to get a player object, we are going to have to use the game.Players.PlayerAdded event. this event is fired when a player joins the game.

also MarketplaceService.PromptGamePassPurchaseFinished if the item is a gamepass.

 

local passId = 5888493 
local marketplaceService = game:GetService("MarketplaceService")
local Amount = 20000

game.Players.PlayerAdded:Connect(function(plr)
	local DiamondDollors = plr.leaderstats.DiamondDollors
	marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player,assetId,isPurchased)
		if isPurchased then
			if plr == player then
				if assetId == passId then
					DiamondDollors.Value = DiamondDollors.Value + Amount
				end
			end
		end
	end)
end)

2 comments

0

So, this script will function only after a purchase is made with that gamepass ID in-game, right?

0

yes

This discussion is preserved as it was. New answers, comments, and votes are closed.