How do I show an in app purchase price in local currency - coronasdk

Just wondering what I need to call to show the price in local currency of my in app purchase. Eg, in Australia I would like to have a button / label that shows $1.29 (tier 1) but if somebody in North America is using the app, it will show $0.99 (tier 1).
This is for iOS.
Thanks in advance.

When you use the store library, you can call the function "loadProducts" to get the available items for sale. Each item entry has a field "localizedPrice" that is a string representing the price according to the user's apple store.
for example, for ios:
local productIds = {
--array of your product identifiers, as you defined them in iTunes Connect
}
local function loadProductsCallback( event )
local validProducts = event.products
local invalidProducts = event.invalidProducts
if validProducts ~= nil then
for i = 1, #validProducts do
local currentItem = validProducts[i]
-- here do what you want with currentItem.localizedPrice
end
end
end
local store = require("store")
store.init("apple", storeListener)
if store.isActive and store.canLoadProducts then
store.loadProducts(productIds, loadProductsCallback)
End
You can read more about it in the documentation:
http://docs.coronalabs.com/api/library/store/loadProducts.html

Related

“Value is not a valid member of model” error, when it 100% is

So, I’m trying to make it so when a player claims a tycoon, the number of the tycoon is saved in an intvalue that gets parented to their character. There is a button that should only function if the player owns the tycoon it is in. The value is name “Tycoon”. When I try to do
local click = workspace.Button1.ClickDetector
click.MouseClick:Connect(function(player)
if player.Character.Tycoon.Value == 1 then
…
end
end)
the game throws me an error:
“Tycoon is not a valid member of Model “Workspace.PlatinumAdventurer(my user)””
When I run the project, I can see that the intvalue is 100% in the character.
I have tried using :waitforchild, but it doesn’t work. I’ve also tried to, instead of doing player.Character, doing
local playerName = player.Name
…
if workspace.playerName.Tycoon.Value…
Any help would be appreciated, thank you?
It might have to do with the model structure.
You can try checking if player has a character first, then find the IntValueTycoon parented to the character. Once the IntValue is found, it should retrieve it's actual value and perform action if tycoonValue == 1
local click = workspace.Button1.ClickDetector
click.MouseClick:Connect(function(player)
local character = player.Character
if character and character:FindFirstChild("Tycoon") then
local tycoonValue = character.Tycoon.Value
if tycoonValue == 1 then
...
end
end
end)

DataStoreService Issues

bear with me but this is my first post so unsure of general formats etc.
I am currently testing with my first data store system on ROBLOX. After following a tutorial I managed to get a data store to store, load and save a cash value specified to the userID that went into the leaderboard. I am currently trying to edit the system to work with a value saved to the player, rather than a leaderstat value but it doesn't seem to be either loading or saving the value correctly.
If you take a look at the code below it is set up to print out strings to confirm the saving/loading has worked but it does not either load or save the value correctly.
Currently the script loads the value and a separate localscript displays the value as text to a display gui with two buttons than can either increase or decrease the value.
I am very new to ROBLOX Lua, so any help would be greatly appreciated.
Script located within ServerScriptService:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("DataStore")
local data2
game.Players.PlayerAdded:Connect(function(player)
local SusTune = Instance.new("Folder")
SusTune.Name = "SusTune"
SusTune.Parent = player
local fcamber = Instance.new("IntValue")
fcamber.Name = "fCamber"
fcamber.Parent = SusTune
local success, errormessage = pcall(function()
data2 = myDataStore:GetAsync(player.UserId.."-FC")
end)
if success then
fcamber.Value = data2
print("Successfully loaded data!")
print(fcamber.Value)
else
warn(errormessage)
print("There was an error while getting your data.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-FC",player.SusTune.fCamber.Value)
end)
if success then
print("Data saved successfully!")
else
print("There was an error when saving data.")
warn(errormessage)
end
end)
LocalScript located within gui button:
local counterDisplay = script.Parent
local increaseButton = script.Parent.Parent.Increase
local decreaseButton = script.Parent.Parent.Decrease
local counter = game.Players.LocalPlayer.SusTune.fCamber.Value
counterDisplay.Text = counter
increaseButton.MouseButton1Click:Connect(function()
print("+1 added")
counter += 1
game.Players.LocalPlayer.SusTune.fCamber.Value = counter
counterDisplay.Text = counter
end)
decreaseButton.MouseButton1Click:Connect(function()
print("-1 added")
counter -= 1
game.Players.LocalPlayer.SusTune.fCamber.Value = counter
counterDisplay.Text = counter
end)
I have personally tried comparing this version to the working cash version but cannot work out why its not working. If its something really silly or simple I am going to hate myself and feel like an idiot, but been staring at it for an hour so need some help. Many thanks in advance :)
EDIT:
I think I have managed to narrow down the error.
When running the game and using console the buttons do not change the fCamber.Value BUT when running it in studio you can visually see the value changing with each button click, also confirmed by the ‘+/-1 added’ which is outputted in both studio and Roblox console.
After using SetASync in the main script, I had the script output the value it had just saved using a GetASync immediately afterwards (for testing purposes) and it seems the value itself is not saving to the data store.
I’m not sure if this extra data will benefit or not, but thought it would be a good detail to add.
z32

How can I make something happen when I buy a DevProduct (Roblox LUA)

I have made a major part of the code, but I am stuck in the important part. Here is what I'm doing:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local productID = 1218445231
local productInfo = MarketplaceService:GetProductInfo(productID, Enum.InfoType.Product)
script.Parent.MouseButton1Click:Connect(function()
local function promptPurchase()
local player = Players.LocalPlayer
MarketplaceService:PromptProductPurchase(player, productID)
purchased = true
end
end)
if purchased == true then
--stuck here (if you don't understand, the tsunami that I've made is supposed to become visible and start moving towards the map, however the part is in "Workspace". The button is in "StarterGUI". Please help.)
end
EDIT: Now updated the code, still don't know what to do. Do I get the workspace Service? If so, how do I code it that it sets the transparency of the tsunami to "0", and starts moving? This is my code:
local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
local productID = 1218445231
script.Parent.MouseButton1Click:Connect(function()
PurchaseEvent:FireServer(productID)
end)
if MarketplaceService:PlayerOwnsAsset(1218445231) then
--Make tsunami become visible and start moving
end
In the docs for MarketplaceService, there's a note
the callback ProcessReceipt which must be well defined so that transactions do not fail.
After the purchase prompt is shown to the player, ProcessReceipt is called with the results of their choice. So that callback is how you make something happen after a user buys something.
A good structure for this kind of code is to have product purchases handled in a server Script, and to have UI elements communicate purchase intents using RemoteEvents. So do some setup :
Create a RemoteEvent in ReplicatedStorage, name it something like "PurchaseEvent"
Create a Script in ServerScriptService
Then update your LocalScript to look like this :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
local productID = 1218445231
-- listen for when players click the button to buy the product
script.Parent.MouseButton1Click:Connect(function()
-- tell the server that we want this product
PurchaseEvent:FireServer(productID)
end)
Then add this code to the server Script to handle the purchase :
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.PurchaseEvent
-- listen for when players want to buy things :
PurchaseEvent.OnServerEvent:Connect(function(player, productID)
-- show the purchase prompt to the user
MarketplaceService:PromptProductPurchase(player, productID)
end)
-- Define what should happen if a player buys something
-- NOTE - ADD FUNCTIONS FOR EACH SPECIFIC PRODUCT
local productHandlers = {}
productHandlers[1218445231] = function(player)
print("TODO : spawn a tsunami")
end
-- Listen for when someone clicks on any of the buttons in the purchase prompt
MarketplaceService.ProcessReceipt = function(receiptInfo)
-- Find the player who made the purchase in the server
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game, don't charge them yet
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Look up handler function from 'productHandlers' table above
local handler = productHandlers[receiptInfo.ProductId]
if not handler then
error(string.format("No handler is defined for %d", receiptInfo.ProductId))
end
-- Call the handler function and catch any errors
local success, result = pcall(handler, player)
if not success or not result then
local message = table.concat({
"Error occurred while processing a product purchase",
" - ProductId: " .. tostring(receiptInfo.ProductId),
" - Player: " .. player.Name,
}, "\n")
warn(message)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
return Enum.ProductPurchaseDecision.PurchaseGranted
end
If you want to check if a user has bought something in the past and you don't want to charge them again, you can always check before you show the purchase prompt with the MarketplaceService:PlayerOwnsAsset function.

How to give money to player which username is stored in a string value - Roblox lua

So I'm making a game on Roblox where you can pick up objects and sell them. however, the selling script is a normal Script (ran on the server), and I can't use
Game:GetService("Players").LocalPlayer
to find who to give the money to. the object that the user picks up has an
Owner
value, and when they touch it, it changes it to their username. so when the object touches the selling part, it looks at the owner, and gives the money to them (which is stored in a number value called Owner).
Here is my current code:
local part = script.Parent
local function onPartTouched(otherPart)--otherPart is the part that touched it
if otherPart:FindFirstChild("Owner") == nil then
else
local owner = game.Players..otherPart.Owner.Value
getowner.leaderstats.Bucks.Value = getprice.leaderstats.Bucks.Value + otherPart.Price.Value
otherPart.Parent = game.ServerStorage
end
end
part.Touched:Connect(onPartTouched)
you can just do game.Players[value.Value]
just use
Game.Players.LocalPlayer
also just writing #agents answer too in proper format.
local part = script.Parent
local function onPartTouched(otherPart)
if otherPart:FindFirstChild("Owner") == nil then
else
local owner = game.Players[otherPart.Owner.Value]
getowner.leaderstats.Bucks.Value = getprice.leaderstats.Bucks.Value +otherPart.Price.Value
otherPart.Parent = game.ServerStorage
end
end
part.Touched:Connect(onPartTouched)

Roblox In-Game Ban System

I am trying to make an in-game system for banning players. I have a button that fires a remote event with a player's name and a message for why they were banned. But every time I hit the button, I get this error :
ServerScriptService.Event_Handler:21: attempt to call a nil value
I have no idea why this is not working can someone help me understand what's going wrong?
EVENT_HANDLER
local dss = game:GetService("DataStoreService")
local bands = dss:GetDataStore("banDataStore")
BanPlayer.OnServerEvent:Connect(function(player, playertoban, reason)
local pui = player.UserId
local success, errormessage = pcall(function()
bands:SetAsync("Banned-", pui, true)
end)
if success then
print("Player Successfuly Banned")
end
game.Players:FindFirstChild(playertoban):Kick(reason)
end)
Since you are searching for players by name, it's possible that you could be spelling the name wrong. In that case, game.Players:FindFirstChild() will return nil. You can sanitize this call by making sure that the player exists before calling Kick()
Also, as a side note, it looks like you are banning the player that calls the BanPlayer RemoteEvent, not the one whose name is stored in playertoban.
local dss = game:GetService("DataStoreService")
local bands = dss:GetDataStore("banDataStore")
BanPlayer.OnServerEvent:Connect(function(player, playertoban, reason)
-- check that playertoban is a real player's name
local bannedPlayer = game.Players:FindFirstChild(playertoban)
if not bannedPlayer then
warn("Could not find a player named " .. playertoban)
return
end
-- record their user-id so we can ban them when they rejoin
local pui = bannedPlayer.UserId
local success, errormessage = pcall(function()
bands:SetAsync("Banned-", pui, true)
end)
if success then
print(playertoban .. " Successfully Banned")
else
warn(string.format("Failed to ban %s permanently with error : %s", playertoban, errormessage))
end
-- remove them from the game
bannedPlayer:Kick(reason)
end)

Resources