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

Script not working in game...?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

This script doesn't work in game..?

I get this error : attempt to locate 'localplayer' (a nil value) on line 2

this script needs to stay as a regular script, so how can I fix this?

local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local cash = game.Players.LocalPlayer.leaderstats
enable = true

function CompletePurchase()
    if enable == true then
    enable = false
end
   cash.Cash.Value = cash.Cash.Value + 10
end

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 23429504
enable = true

MarketplaceService.ProcessReceipt = function(receiptInfo) 


    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then


            if receiptInfo.ProductId == productId then

                CompletePurchase()
            end
        end
    end 

    local playerProductKey = "plr_" .. receiptInfo.PlayerId .. "_pur_" .. receiptInfo.PurchaseId
    ds:IncrementAsync(playerProductKey, 1)  

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Right off the bat, the problem is this:

You've made a variable for the player in line one.

But then you've made a variable for the player's leaderstats without using the player variable that you made.

local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local cash = player.leaderstats -- I recommend you to rename the variable, as its name is inaccurate, as it does not define "leaderstats" itself

game.Players.LocalPlayer can only be used in a local script. That's why the script returned an error.

0
I now get this error : leaderstat is not a valid member of playergui UnleashedGamers 257 — 9y
0
Then the "player" variable is also inaccurate, as "PlayerGui" was returned from line 1. Just add another parent, and that'll work. Redbullusa 1580 — 9y
Ad

Answer this question