I'm wondering another way to access a LocalPlayer through a regular script, How would I go about doing this? I'm wanting to do this so I can add the value when buying developer products.
game.Players.LocalPlayer.MoneyValue
That's what I'm trying to do only through a Script, How would I accomplish this?
Here's the developer product script I'm wanting it to work with
local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local pid1 = 363906114 local pid2 = 363906921 local pid3 = 365773688 local pid4 = 365773990 local pid5 = 365774250 local pid6 = 365774578 local sid = 364007259 -- StarterPack local Money = -- However I get to the LocalPlayer -- MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == pid1 then Money.Value = Money.Value + 1000 elseif receiptInfo.ProductId == pid2 then Money.Value = Money.Value + 5000 elseif receiptInfo.ProductId == sid then Money.Value = Money.Value + 10750 elseif receiptInfo.ProductId == pid3 then Money.Value = Money.Value + 10000 elseif receiptInfo.ProductId == pid4 then Money.Value = Money.Value + 25000 elseif receiptInfo.ProductId == pid5 then Money.Value = Money.Value + 50000 elseif receiptInfo.ProductId == pid6 then Money.Value = Money.Value + 100000 end end end return Enum.ProductPurchaseDecision.PurchaseGranted end
You can just move local Money
into the for loop in the function.
Unless you're going to be using Money
variable outside of the function, you can always just define it inside the function; and even if you're going to be using the Money
variable outside of the function, you can set the variable Money
empty in the beginning like this.
local Money
Then later in your scripts you can access that variable in different blocks.
Now to access the player, you already have a for loop that gets a player.
for i, player in ipairs(game.Players:GetChildren()) do
(you should use GetPlayers instead of GetChildren btw)
Under that you should add the local Money = player.MoneyValue
. Yes, it's really that simple.