How would I charge Robux to turn on RGB lights?

Hey everyone!

Currently, I’m busy making a new game that includes RGB ceiling lights. Now, I’m not going to provide details of the game as I want to keep it exclusively secretive until I announce it, however I wanted to charge players Robux for using this feature for various reasons (this may change but for now this is the case).

I’ve written all the scripts by myself with little help from the Internet, which is a great thing for me. I have no issues at all writing a script that turns on a light via ProximityPrompts, it’s just adding in that “pay to use” function that I’m having trouble with.

local RGB1 = script.Parent.RGB1
local RGB2 = script.Parent.RGB2
local SurfaceLight = RGB1.SurfaceLight
local ProximityPrompt = script.Parent.RGBSwitch.ProximityPrompt
local id = 135483662

local Bool = true

--ProximityPrompt.Triggered:Connect(function()

--	if Bool == true then
--		RGB1.SurfaceLight.Enabled = false
--		RGB1.Transparency = 1
--		RGB2.SurfaceLight.Enabled = false
--		RGB2.Transparency = 1
--		Bool = false
--	elseif Bool == false then
--		RGB1.SurfaceLight.Enabled = true
--		RGB1.Transparency = 0
--		RGB2.SurfaceLight.Enabled = true
--		RGB2.Transparency = 0
--		Bool = true
--	end

--end)

-----------

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and id == ido then
		ProximityPrompt.Triggered:Connect(function()

		if Bool == true then
		RGB1.SurfaceLight.Enabled = false
		RGB1.Transparency = 1
		RGB2.SurfaceLight.Enabled = false
		RGB2.Transparency = 1
		Bool = false
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,id) then
				
		elseif Bool == false then
		RGB1.SurfaceLight.Enabled = true
		RGB1.Transparency = 0
		RGB2.SurfaceLight.Enabled = true	
		RGB2.Transparency = 0
		Bool = true
	end
end)

Important to Note

  • The commented code works but the user is not required to pay to use the RGB feature.
  • I’ve duplicated the code and tried to add in a gamepass purchase, which is where my issue lies.
  • If for whatever reason this doesn’t work out, I can always use the previous code! This way I won’t have to start over and it makes it easy for members here on CT to read the code.
  • I plan to recycle the new code for a jukebox music system at some point, if I can resolve this problem.

Hey, I’m a bit confused on what exactly you want to achieve but I’ve tried my best to understand you, would something like this be feasible:

local RGB1 = script.Parent.RGB1
local RGB2 = script.Parent.RGB2
local SurfaceLight = RGB1.SurfaceLight
local ProximityPrompt = script.Parent.RGBSwitch.ProximityPrompt
local id = 135483662

local Bool = true

ProximityPrompt.Triggered:Connect(function(player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
		if Bool == true then
			RGB1.SurfaceLight.Enabled = false
			RGB1.Transparency = 1
			RGB2.SurfaceLight.Enabled = false
			RGB2.Transparency = 1
			Bool = false
		elseif Bool == false then
			RGB1.SurfaceLight.Enabled = true
			RGB1.Transparency = 0
			RGB2.SurfaceLight.Enabled = true
			RGB2.Transparency = 0
			Bool = true
		end
	else
		print("User doesn't own game pass.")
	end
end)

1 Like

Hi!

Sorry if the post was unclear, I’ll try to make it clearer next time for better understanding. And thanks for the script, it works perfectly! I’m assuming you can replace the “print” statement with code that opens the purchase prompt. :+1:

(Marked your post as solution)

Oh, yeah:

For gamepass:

local MarketPlaceService = game:GetService("MarketplaceService")
MarketPlaceService:PromptGamePassPurchase(Player, GamepassId)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.