Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make these two codes work together?

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?

1 comment

0

you will need remote events

1 answer

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)

1 comment

0

No explanation? No accepted answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.