You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’m working on a small cashgrab game, and have been asked to script a vip gamepass, which includes a vip lounge area.
What is the issue? Include screenshots / videos if possible!
I’m using a LocalScript in StarterPlayerScripts to constantly detect when the player has the gamepass, then if true, set the CanCollide of a door part to False.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried moving the LocalScript, changing the way I made a infinite loop, and resorting to asking ChatGPT. None of which worked (Obviously)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Heres my code
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local gamePassID = 1102021011
local part = workspace.Spawn.VIP.vip:WaitForChild("Door")
local function updateCollision()
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) then
part.CanCollide = false
else
part.CanCollide = true
end
end
-- Run initially
updateCollision()
-- Periodically check (every 5 seconds)
while true do
task.wait(5) -- Prevents game freeze
updateCollision()
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
If the game utilizes “StreamingEnabled” the current client may not be able to find the part as shown below.
local part = workspace.Spawn.VIP.vip:WaitForChild("Door")
I’d recommend detecting when the player touches the door/part using a .Touched event and then doing the MarketPlace check. This will eliminate the client have the find the door part. BasePart | Documentation - Roblox Creator Hub
If you don’t want to do that, I’d recommend doing the “worse of the worse;”
local part = workspace:WaitForChild("Spawn"):WaitForChild("VIP"):WaitForChild("vip"):WaitForChild("Door")
-- please don't use this code
This will yield the rest of your code until it can find the part or after the recursive time has passed (which is currently set to default).
Hey! As @twinkyman26 mentioned, it is probably an issue related to StreamingEnabled. Since the door might not be loaded, the script might raise an error.
To avoid this you can also make it so the door is always loaded in. To do this, select the model the door is in and set the property “ModelStreamingMode” to Persistent. This post refers to this property:
You haven’t specified any errors, so I will assume that this has no connection to instance streaming. What is of valuable note is that MarketplaceService:UserOwnsGamePassAsyncdoes not recognize test purchases in Roblox Studio. It uses official ownership records to make its judgments. Additionally, UserOwnsGamePassAsync implements a local cache to improve the response times of subsequent requests. If your initial request turned up false, this value can be cached, leading to negative ownership responses despite later purchase. Altogether, these nuances make your strategy inadequate. Instead, use MarketplaceService.PromptGamePassPurchaseFinished to learn when the game-pass is purchased in-game, and check its “wasPurchased” parameter for the green light to toggle the door