UevKF8zjRV_WEtpJsXhr
We use cookies on this site to enhance your user experience

Monetization

Monetization

Players of all ages love to show off how cool their character looks in a game. For this top down game, let’s give players a particle effect if they purchase a Game Pass. The code below will use the value you give gamePassId to add a huge fireball to their ship while they play.

Checking for Player Game Passes

HasGamepassChecker will check if players already have the game pass you’ve created using a ModuleScript.

  1. In ReplicatedStorage, create a new ModuleScript.
  2. Rename the ModuleScript HasGamepassChecker.
  3. Copy this code in the code sample below to this new ModuleScript:

Adding the Effect to the Game

  1. Go to ServerScriptService, and open PlayerShipHandler
  2. Add the following variables to the script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Local HasGamepassChecker = require(ReplicatedStorage:FindFirstChild("HasGamepassChecker")

-- Unique number of the GamePass you created
local GAMEPASS_ID = 0000000 -- Replace this with your GamePass’s ID
-- Determines the heat (how fast the flame moves) and size
local FIRE_HEAT = 20
local FIRE_SIZE = 30
  1. Add a function above onCharacterAdded() called gamePassVerification() with a parameter named player that will store the player.
-- Called to check if a joining player has bought the GamePass with the id from gamePassId
local function gamePassVerification(player)

end
  1. Call HasGamepassChecker’s getPlayerHasPass() function to see if the player owns the pass.
local function gamePassVerification(player)
	if HasGamepassChecker:getPlayerHasPass(player.UserId, GAMEPASS_ID) then
	end
end
  1. Under the if statement, spawn a Fire object and set it’s heat and size.
local function gamePassVerification(player)

	if HasGamepassChecker:getPlayerHasPass(player.UserId, GAMEPASS_ID) then
		local fireEffect = Instance.new("Fire", player.Character.HumanoidRootPart)
		fireEffect.Heat = FIRE_HEAT
		fireEffect.Size = FIRE_SIZE
	end
end
  1. Add an else statement, printing to the console that there was an error.
local function gamePassVerification(player)
	if HasGamepassChecker:getPlayerHasPass(player.UserId, GAMEPASS_ID) then
		local fireEffect = Instance.new("Fire", player.Character.HumanoidRootPart)
		fireEffect.Heat = FIRE_HEAT
		fireEffect.Size = FIRE_SIZE
	else
		print("player either doesn't have pass or there was an error and player didn't want to retry")
	end	
end

The last step above can be changed to do other unique things instead. For example, you can create a Trail effect or a Particle Emitter instead of a Fire.


These documents are licensed by Roblox Corporation under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Roblox, Powering Imagination, and Robux are trademarks of Roblox Corporation, registered in the United States and other countries.