Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
BryanFehr 133
5 years ago

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!

0
im not really sure but i think this needs to be script not localscript and you can't use game.Players.LocalPlayer HappyTimIsHim 652 — 5y
0
This is true, ServerScripts can’t reference game.Players.LocalPlayer because it doesn’t have one Ziffixture 6913 — 5y
0
Not due to FE. But because the server has no player of its own. User#24403 69 — 5y
0
tell a parent to get the local child and you see what happens theking48989987 2147 — 5y
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! BryanFehr 133 — 5y

1 answer

Log in to vote
0
Answered by
farizarps 132
5 years ago

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)
0
So, this script will function only after a purchase is made with that gamepass ID in-game, right? BryanFehr 133 — 5y
0
yes farizarps 132 — 5y
Ad

Answer this question