Stop asking everyone so they will do something for you, learn by yourself, you can’t just get the help you want everytime, not everyone is ready to tell you something or especially giving an example code. It looks like you’re here just for getting free help and easy scripts
I am Learning to code, I just know on Some basics one.
And i’m asking for some scripts is because when i paste it, I study it and memorise on what they did to accomplish that code that made my game Successful.
I’m not at monetization yet, but basically you have to bring up a purchase prompt within the death screen code. You will have to make a developer product gamepass on the website. Then you need to take the ID from the URL and copy it into your game, so when you call the routine to bring up the prompt, it knows what the price is and such. There’s a lot to it. Here’s my module, and I’ve tested this code up to the purchase prompt.
--[[
Created by Maelstorm_1973
This module deals with purchases that requires real money
to make. Also contains the store items definitions as well.
--]]
local monetizationMod = {}
-- ******** Requirements
-- Required Game Services and Facilities
local playerService = game:GetService("Players")
local dataService = game:GetService("DataStoreService")
local insertService = game:GetService("InsertService")
local marketService = game:GetService("MarketplaceService")
local collectionService = game:GetService("CollectionService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local purchaseHistory = dataService:GetDataStore("PurchaseHistory")
-- Scripting Support
local scriptService = game:GetService("ServerScriptService")
local coreLibs = scriptService:WaitForChild("ServerHandler", 10)
if not coreLibs or coreLibs == nil then
error("Core library script load failure.")
end
-- Required Core Library Scripts
local playerDataStoreMod = require(coreLibs.PlayerDataStore)
local enums = require(coreLibs.Enumerations)
-- ******** Local Data
-- This table contains data for all the items that can be purchased in
-- the ingame store. This includes items purchased with ingame currency
-- and Robux.
local StoreItems = {
speedCoil = {
Name = "Speed Coil";
Type = Enum.InfoType.GamePass; -- Product type (Developer or Gamepass)
Class = Enum.GearType.PowerUps; -- Product class
Currency = Enum.CurrencyType.Robux; -- Purchase currency type
Storage = enums.StorageType.Backpack; -- Item storage type
Price = 100; -- Price
Consumable = false; -- True if consumable
StoreItem = true; -- True if item appears in the store.
ProductId = 37977495; -- Roblox product ID (for gamepass or dev prod)
AssetId = 99119158; -- Asset ID if applicable
AssetCode = "SpringPotion"; -- Item name in replicated storage
Active = false; -- Indicates if product can be purchased
Equip = false; -- Give item to player
};
gravityCoil = {
Name = "Gravity Coil";
Type = Enum.InfoType.GamePass;
Class = Enum.GearType.PowerUps;
Currency = Enum.CurrencyType.Robux;
Storage = enums.StorageType.Backpack;
Price = 100;
Consumable = false;
StoreItem = true;
ProductId = 37977624;
AssetId = 16688968;
Active = true;
Equip = false;
};
radio = {
Name = "Radio";
Type = Enum.InfoType.GamePass;
Class = Enum.GearType.SocialItems;
Currency = Enum.CurrencyType.Robux;
Storage = enums.StorageType.Backpack;
Price = 0;
Consumable = false;
StoreItem = true;
ProductId = 37977733;
AssetId = 212641536;
Active = false;
Equip = false;
};
Coins100DV = {
Name = "100 Coins";
Type = Enum.InfoType.Product;
Class = Enum.GearType.SocialItems;
Currency = Enum.CurrencyType.Robux;
Storage = enums.StorageType.PlayerData;
Price = 25;
Consumable = true;
StoreItem = true;
ProductId = 1256922567;
AssetId = 0;
Index = "Coins";
Value = 100;
Active = true;
Equip = false;
};
Coins100 = {
Name = "100 Coins";
Type = Enum.InfoType.GamePass;
Class = Enum.GearType.SocialItems;
Currency = Enum.CurrencyType.Robux;
Storage = enums.StorageType.PlayerData;
Price = 25;
Consumable = true;
StoreItem = true;
ProductId = 37977806;
AssetId = 0;
Index = "Coins";
Value = 100;
Active = false;
Equip = false;
};
}
-- ******** Private Functions/Methods
-- Recursively copies data.
local function recursiveCopy(dataTable)
local tableCopy = {}
for index, value in pairs(dataTable) do
if type(value) == "table" then
value = recursiveCopy(value)
end
tableCopy[index] = value
end
return tableCopy
end
-- ******** Public Functions/Methods
-- Returns the store database.
monetizationMod.getStoreItems = function()
local tableCopy = recursiveCopy(StoreItems)
return tableCopy
end
-- Searches the store database for an item with the given product ID.
monetizationMod.searchStoreProductId = function(productId)
local tableCopy
for _, itemData in pairs(StoreItems) do
if itemData.ProductId == productId then
tableCopy = recursiveCopy(itemData)
return tableCopy
end
end
return nil
end
-- Searches the store database for an item with the given asset ID.
monetizationMod.searchStoreAssetId = function(assetId)
for _, itemData in pairs(StoreItems) do
if itemData.AssetId == assetId then
return itemData
end
end
return nil
end
-- Call this function in the CharacterAdded event function of the
-- Initialize module to award gamepass tools
monetizationMod.givePremiumTools = function(player)
local key = player.UserId
for _, item in pairs(StoreItems) do
if item.Equip and item.Equip ~= nil then
local ownsPass = marketService:UserOwnsGamePassAsync(key, item.ProductId)
local hasTag = collectionService:HasTag(player, item.ProductId)
if hasTag or ownsPass then
monetizationMod.addItemToPlayer(player, item, true)
end
end
end
end
-- Adds an item to either the player's backpack or to their
-- datastore. In the case of backpack, checks to see if the
-- item is already in the backpack. itemData is the store
-- data record from the StoreItems table above.
monetizationMod.addItemToPlayer = function(player, itemData)
local errmsg
if itemData.Storage == enums.StorageType.Backpack then
-- Item stored in backpack
if itemData.AssetId > 0 then
-- Item has a Roblox Asset ID
local asset = insertService:LoadAsset(itemData.AssetId)
if not asset then
errmsg = "Invalid item asset ID: " .. itemData.AssetId
return false, errmsg
end
local tool = asset:FindFirstChildOfClass("Tool")
if not tool then
asset:Destroy()
errmsg = "Unable to find tool item. ProductID: " .. itemData.ProductId
return false, errmsg
end
-- Check if player already has item in backpack.
for _, inventory in pairs(player.Backpack:GetChildren()) do
if inventory.Name == tool.Name then
asset:Destroy()
errmsg = "Player already has item in their backpack: " .. itemData.ProductId
return false, errmsg
end
end
tool.Parent = player.Backpack
asset:Destroy()
return true
else
-- Item does not have a Roblox Asset ID (eg. custom item)
local asset = itemData["AssetCode"]
if not asset then
errmsg = "Item does not have an asset code: " .. itemData.ProductId
return false, errmsg
end
local tool = asset:Clone()
if not tool then
errmsg = "Unable to clone tool: " .. itemData.ProductId
return false, errmsg
end
-- Check if player already has item in backpack.
for _, inventory in pairs(player.Backpack:GetChildren()) do
if inventory.Name == tool.Name then
asset:Destroy()
errmsg = "Player already has item in their backpack: " .. itemData.ProductId
return false, errmsg
end
end
tool.Parent = player.Backpack
return true
end
elseif itemData.Storage == enums.StorageType.PlayerData then
playerDataStoreMod.dataIncrement(player, itemData.Index, itemData.Value)
return true
else
errmsg = "Invalid data storage type:" ..
"\nItem: " .. itemData.Name ..
"\nID: " .. itemData.ProductId ..
"\nAsset: " .. itemData.AssetId
return false, errmsg
end
end
-- Grants the player a premium item that was purchased with Robux.
monetizationMod.grantPremiumItem = function(player, receiptInfo)
local itemData = monetizationMod.searchStoreProductId(receiptInfo.ProductId)
if not itemData then
-- Item was not found, purchase failed.
print("Product was not found in store database: " .. receiptInfo.ProductId)
return false
end
-- Check to make sure the item is active. If not, fail
-- the purchase.
if not itemData.Active then
-- Item is not active in game.
print("Product ID is not active in game: " .. itemData.ProductId)
return false
end
-- Add a tag to the collection service if the item is
-- not a consumable.
if not itemData.Consumable then
collectionService:AddTag(player, itemData.ProductId)
end
-- Store item to player
local result, errmsg = monetizationMod.addItemToPlayer(player, itemData)
if not result then
collectionService:RemoveTag(player, itemData.ProductId)
print(errmsg)
return false
end
-- Item has been granted.
return true
end
-- Processes a receipt record
-- This is called from Roblox when a purchase is made
function marketService.ProcessReceipt(receiptInfo)
-- Build the product key by using the player ID and
-- purchase ID.
local playerProductKey = receiptInfo.PlayerId ..
"_" .. receiptInfo.PurchaseId
-- Check the datastore to see if this was purchased
-- before.
local purchased = false
local success, errmsg = pcall(function()
purchased = purchaseHistory:GetAsync(playerProductKey)
end)
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errmsg)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Locate player in the server
local player = playerService:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game. This function
-- will be called again when they return.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Grant the player their product.
local success, result = pcall(function()
monetizationMod.grantPremiumItem(player, receiptInfo)
end)
if not success or not result then
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Record the purchase so it isn't granted again.
success, errmsg = pcall(function()
purchaseHistory.SetAsync(playerProductKey, true)
end)
if not success then
error("Unable to record purchase data: " .. errmsg)
end
-- IMPORTANT: Tell Roblox that the purchase was processed
-- successfully.
return Enum.ProductPurchaseDecision.PurchaseGranted
end
-- Testing
monetizationMod.testPurcahse = function(player)
local receipt = {
ProductId = 37977624;
PlayerId = player.UserId;
PurchaseId = "9038JFLJLDHJFDAAPQ834857";
}
local result = monetizationMod.grantPremiumItem(player, receipt)
--local result = marketService.ProcessReceipt(receipt)
print(result)
end
return monetizationMod
This code was modified from a book that I bought off Amazon about writing games for Roblox. This also follows the online tutorials from Roblox too. There are a number of requirements that you must adheir to to make this work. My code will not work verbatim in your environment, but it should give you a starting point for what to do.
Everyone was a beginner at some point, even me and you. How are people going to learn if they don’t ask questions?
I found something at YT, A death screen with a Promo purchase, I modified it a little. Now it worked
But I have a question, Do you know how to add any tweenings to it?
I’ve learned scripting without asking much really, maybe there was some questions a year ago and that’s all. I was searching for solutions through many topics, answers, i tried many things and i’ve learned from that a lot
Edit: i’m not trying to be rude, it’s just really annoying when a person asking 10000 times for an example code. Why don’t you stick around and find out by yourself? It’s always better, plus you will learn the logic
I modified a script i found on Youtube
Video (I just used Roblox Default)
robloxapp-20220925-1023004.wmv (5.1 MB)
Sorry if the Vid is Bad quality, I asked my Friend CalypsoGames to test it out for me yesterday and that’s the vid.
Game Features and added:
- Working StaminaUI and Shift to run
- Working HealthUI (Tested it on a Zombie)
- Camera Bobbing and tilting
- Working Advanced Flashlight (Like Apeirophobia)
- Working Introduction Interface (IntroGui)
- Working Prompt Purchase Revive for 50 Robux
- Working Tp to Lobby
- Smooth moves (Smoothens the Player’s move)
And that’s it!
EDIT: Some of the code of each features is modified by me, I do not own the scripts of it but i modified it.
Maybe it’s me, but coding comes easy for me. I got started in computers and electronics when I was 10. I’m pushing 50 now. I’ve watched the computer evolve from a hobby to serious business today. I remember gold old MS-DOS, and even CP/M. Pre-Windows stuff. Back then, unless you spent $5,000 for one of those Apple MACs, you were left with a command line interface. I do all my Unix work via command line and vi.
Don’t get me wrong, I do understand the annoyance, which is why I put limits on how much I’m going to help with. With that, if they want code, I’ll give them some code, but then they have to work it out for themselves after that. I’ve had people ask questions, and I told them “You have to adapt it to your environment.”
For those of us who are old hat at this stuff, we tend to take on the mantle of teacher. To show the next generation of coders how it’s done and why it’s done that way. It’s a mantle that I’ve been wearing for quite some time.
Cheers
That doesn’t matter; they still can ask.
You are misunderstanding me, i’m not saying that they can’t ask
Ayeee, Wait. No need to fight here. To be clear, I get some example scripts. And put it on my game, And i learn on how they did it. Sometimes i Modify it.
Clear?
Code it so when you crouch the players’ HipHeight goes down. Then when you stop crouching it goes back to normal.
Here’s an example using a starting HipHeight of 3 and a system of holding the key down to crouch.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
humanoid.WalkSpeed = 8
humanoid.HipHeight = 0.3
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
humanoid.WalkSpeed = 16
humanoid.HipHeight = 3
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.