Selling Bonuses
Selling Bonuses
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.
- In ReplicatedStorage, create a new ModuleScript.
- Rename the ModuleScript HasGamepassChecker.
- Copy this code in the code sample below to this new ModuleScript:
HasGamepassChecker Code Sample »
Adding the Effect to the Game
- Go to ServerScriptService, and open PlayerShipHandler
- 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
- Add a function above
onCharacterAdded()
calledgamePassVerification()
with a parameter namedplayer
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
- 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
- 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
- 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.
Previous Creating a Game Pass