Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a gamepass that removes a wall?

It is all in the question really. I've tried multiple ways as such as using a gui rather than touching the part, the gui worked better as it actually prompted the purchas unlike the part being touched. To prompt the purchase i have put a local script into a frame, which includes this code :

script.Parent.TextButton.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
end)

local UserInputService = game:GetService("UserInputService")
local frame = script.Parent
local topBar = frame:WaitForChild("TopBar")
local Camera = workspace:WaitForChild("Camera")
local DragMousePosition
local FramePosition
local Draggable = false

topBar.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		Draggable = true
		DragMousePosition = Vector2.new(input.Position.X, input.Position.Y)
		FramePosition = Vector2.new(frame.Position.X.Scale. frame.Position.Y.Scale)
	end
end)

topBar.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		Draggable = false
	end
end)

UserInputService.InputChanged:Connect(function(input)
	if Draggable == true then
		local NewPosition = FramePosition + ((Vector2.new(input.Position.X, input.Position.Y) - DragMousePosition) / Camera.ViewportSize)
		frame.Position = UDim2.new(NewPosition.X, 0, NewPosition.Y, 0)
	end
end)

To make the gamepass actually do something when bought I've put a script into serverscript service which the code for it is :

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local conveyorID = 18801304

game.Players.PlayerAdded:Connect(function(player)
	local success, message = pcall(function()
		hasPass = MPS:UserOwnsGamePassAsync(player.UserId, conveyorID)
	end)
	
	if hasPass then
		print("player has the gamepass")
		
		local conveyorBorder = game.Workspace.MainBuild.MainConveyor.ConveyorBorder
		conveyorBorder.Transparency = 1
		conveyorBorder.CanCollide = false
	end
end)

local function onPromptGamePassPurchaseFinsihed(player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true and purchasedPassID == conveyorID then
		print(player.Name .. " purchased the conveyor gamepass")
		local conveyorBorder = game.Workspace.MainBuild.MainConveyor.ConveyorBorder
		conveyorBorder.Transparency = 1
		conveyorBorder.CanCollide = false
	end
end

MPS.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinsihed)		

The problem is, is that when i tested it out with a game even tho my friend had not bought the wall completely dissapeared. I'm in desprete need of help because if i dont figure out this i can't continue making my game :/. I think it's somewhere in the code but i can't see it, probably because im new to scripting. I'm reasking the question with more context and like i said i went from using a part touch for activating the prompt purchase to a gui.

1 answer

First, put a local script in starterGui and here’s the script:

local MarketplaceService = game:GetService(“MarketplaceService”)
local Player = game.Players.LocalPlayer

local doorPart = game.Workspace.Door.Door
local gamepassId = yourGamepassID

if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then
      print(“Player Owns Pass.”)
      doorPart.CanCollide = false
      doorPart.Transparency = 1
else
       print(“Player Does Not Own Pass.”)
       doorPart.CanCollide = true
       doorPart.Transparency = 0
end

and make sure to replace ‘yourGamepassID’ with the gamepass Id.

Then, make a model inside workspace named Door and inside of Door, add 4 parts in it and name the first Door, the second DoorFrame, and the third and forth name those DoorFrame.

This discussion is preserved as it was. New answers, comments, and votes are closed.