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

how do i make these two codes work together?

Asked by 4 years ago

so my fist code would be this

amount = 1
timedelay = 4
currencyname = "Cash"

while true do
    wait(timedelay)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:FindFirstChild("leaderstats") then
            v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
        end
    end
end

the second code would be this

MPS = game:GetService("MarketplaceService")
id = 553470050 --dev product id
local player = game.Players.LocalPlayer

script.Parent.Text = "100 Cash"
script.Parent.MouseButton1Click:Connect(function()
 MPS:PromptProductPurchase(player, id)
  script.Parent.Text = "Purhasing"
  wait(5)
  script.Parent.Text = "100 Cash"
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
end)

When i do an in-game purchase it adds the cash but then the first code updates it back to the original number. how can i keep the first code to update and add the amount its suppose to?

0
you will need remote events Fad99 286 — 4y

1 answer

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
4 years ago

Put RemoteEvent and normal script in your second code

second code

MPS = game:GetService("MarketplaceService")
id = 553470050 --dev product id
local player = game.Players.LocalPlayer

script.Parent.Text = "100 Cash"
script.Parent.MouseButton1Click:Connect(function()
 MPS:PromptProductPurchase(player, id)
  script.Parent.Text = "Purhasing"
  wait(5)
  script.Parent.Text = "100 Cash"
  script.RemoteEvent:FireServer(player)
end)

Third code ( Normal Script )

script.Parent.RemoteEvent.OnServerEvent:Connect(function(abc,player)
  player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
end)
0
No explanation? No accepted answer. User#24403 69 — 4y
Ad

Answer this question