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

Script works perfectly in client, but not server..?

Asked by 9 years ago

This script works fine is client, but not server.. its in a server script also.

I get this error in my developer console : attempt to index field 'LocalPlayer' (a nil value)

local player = game.Players.LocalPlayer
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


0
LocalPlayer cannot be called from a ServerScript. Muoshuu 580 — 9y
0
What can I change LocalPlayer to? UnleashedGamers 257 — 9y
0
Where exactly is the script located? (Give me the full hierarchy) Muoshuu 580 — 9y
0
It's in StarterGUI, MainGuis, ShopScreen, AddCreditGui, Credits10 (which is a textbutton) UnleashedGamers 257 — 9y
View all comments (2 more)
0
Change it to a LocalScript Senor_Chung 210 — 9y
0
local player = script.Parent.Parent.Parent.Parent.Parent.Parent Goulstem 8144 — 9y

Answer this question