I'm kinda new to scripting, and I wanted to know if this is correct. I haven't seen any errors in the output yet, but I'm not entirely sure it will work.
local buyButton = game.Workspace.Buttons.BuyButton.SurfaceGui.TextButton buyButton.MouseButton1Click:connect(function(clicker) local player = clicker:GetCharacterFromPlayer() local leaderstats = player:FindFirstChild("leaderstats") local user = player.userId local productId = 19251902 Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) local PointsService = Game:GetService("PointsService") local pointsToAward = PointsService:GetAwardablePoints() leaderstats.Diamonds.Value = leaderstats.Diamonds.Value + 10 if ( pointsToAward > 0) then PointsService:AwardPoints(player.userId, 1) end end)
Looks good, but the way you're trying to find the Player
is incorrect. You're going to have to put the SurfaceGui
in StarterGui
in order to find out who the clicking player is. It'll work the same way, just make sure the Adornee
is still the same. When you put it inside the StarterGui
, you can find the player like so-
local buyButton = script.Parent -- place the script inside the button local player = buyButton.Parent.Parent.Parent -- this should be the player buyButton.MouseButton1Click:connect(function() -- there aren't any parameters for MouseButton1Click local leaderstats = player:FindFirstChild("leaderstats") local user = player.userId local productId = 19251902 Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) local PointsService = Game:GetService("PointsService") local pointsToAward = PointsService:GetAwardablePoints() leaderstats.Diamonds.Value = leaderstats.Diamonds.Value + 10 if ( pointsToAward > 0) then PointsService:AwardPoints(player.userId, 1) end end)