Can someone please help me . I need to fix this script so that it works with FE. Currently when I click any button only the first button works but all the others do not.
I realize that I need different events to fire each button but I cannot figure out how to add the different events in with the buttons being in Pairs. Here is the script. Any help would be greatly appreciated.
Local Script
local SaveToDataStore = game.ReplicatedStorage.SaveToDataStore
local player = script.Parent.Parent.Parent.Parent
local money = player.leaderstats.Money
print(script.Parent.Parent.Parent.Parent)
function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end
for _, button in pairs(script.Parent:GetChildren()) do
if button:IsA("TextButton") then
local productId = button.Value.Value
local mps = game:GetService"MarketplaceService"
local NumValue = button.NumValue.Value
button.MouseButton1Click:connect(function()
button.Button:FireServer()
end)
end
end
Sever Script
local SaveToDataStore = game.ReplicatedStorage.SaveToDataStore
local player = script.Parent.Parent.Parent.Parent
local money = player.leaderstats.Money
print(script.Parent.Parent.Parent.Parent)
function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end
for _, button in pairs(script.Parent:GetChildren()) do
if button:IsA("TextButton") then
local productId = button.Value.Value
local mps = game:GetService"MarketplaceService"
local NumValue = button.NumValue.Value
local Event = button.Button
Event.OnServerEvent:connect(function()
mps:PromptProductPurchase(script.Parent.Parent.Parent.Parent, productId)
mps.ProcessReceipt = function(info)
local plr = getPlayerById(info.PlayerId)
if plr and plr:FindFirstChild"leaderstats" and plr.leaderstats:FindFirstChild"Money" then
money.Value = money.Value + NumValue
print ("Second Time It Processes" .. NumValue)
SaveToDataStore:FireServer(money.Value)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end)
end
end

1 comment
Can Someone Please At Least Attempt To Answer This. I am Incredibly Stuck Right Now And Would Appreciate it so Much If Someone Could Help Me