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

Is this correct? [ANSWERED]

Asked by 10 years ago

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

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

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)
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? fahmisack123 385 — 10y
0
No, you shouldn't need a while loop. Does it break? If so, is there output? Ekkoh 635 — 10y
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 fahmisack123 385 — 10y
0
You don't need a while loop. Click it until it doesn't work and then check the output. Ekkoh 635 — 10y
0
ok. I'll PM you if it still doesn't work fahmisack123 385 — 10y
Ad

Answer this question