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

Is this correct? [ANSWERED]

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)

1 answer

✓ Accepted answer

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)

5 comments

0

Alright. Thanks. I now have a small problem, It will only work once, should I add in a while true do loop? Also, Do I need a debounce if I insert one?

0

No, you shouldn't need a while loop. Does it break? If so, is there output?

0

I tried it before in a LocalScript through a free model, It only worked once, Then I added the loop, it froze for some time, but I got to click it multiple times. I want to avoid it to freeze. I added a wait(), still froze. No output

0

You don't need a while loop. Click it until it doesn't work and then check the output.

0

ok. I'll PM you if it still doesn't work

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