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!
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)