Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I delete a ScreenGui if a player does not own a certain game pass?

Asked by 3 years ago

In order to keep my game safe I would like to delete a ScreenGui that I called VIPGui if a player does not own a game pass. If they do own the game pass then I would like the Gui to not be deleted, if that makes sense. I used a local script and inserted it into the VIPGui. I wrote the following:

local MS = game:GetService("MarketplaceService") local gamepassid = 0 (I did insert my real game pass id in studio) if MS:UserOwnsGamePassAsync(game.Players.LocalPlayer.userId, gamepassid) == false then

script.Parent:Destroy()

end

It did not work so I did the same thing again:

local MS = game:GetService("MarketplaceService") local gamepassid = 0 if MS:UserOwnsGamePassAsync(game.Players.LocalPlayer.userId, gamepassid) == false then

game.StarterGui.VIPGui:Destroy()

end

It still did not work. I checked the output and it was not giving any feedback? I did not own the game pass so it should have deleted but it did not, and my friend did own the game pass and it dd not delete either, which is good, but I believe it is because it did not work. If anyone could please explain, I would appreciate that! Thanks.

1 answer

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
3 years ago

Hello Bulder251,

When a player character loads, things in StarterGui are cloned into that player PlayerGui, so you shouldn't be deleting stuff in the StarterGui if you want them only to be taken away from the player. I also recommend making it so if they have the game pass, you clone it, then put it into their PlayerGui. With that said, I recommend making the GUI a parent of ServerStorage.

local Players = game:GetService('Players')
local MarketplaceService = game:GetService("MarketplaceService")

local PassID = 1 -- // Your game pass ID

Players.PlayerAdded:Connect(function(player)
    local GuiPath = PATH -- // The path to your GUI you wanted to be cloned | Don't put it in StarterGui

    if MarketplaceService:UserOwnsGamePassAsync(player.userId, PassID) then
        local CloneGui = GuiPath:Clone()
        CloneGui.ResetOnSpawn = false
        CloneGui.Parent = player.PlayerGui
    end
end)
0
So this would be a local script put into what? Thanks! bulder251 26 — 3y
0
No, this would be a normal script, and inside of ServerScriptService. NotedAPI 810 — 3y
0
Alright thanks, and I would not change anything? I would keep the ScreenGui (VIPGui) in the StarterGui with it's contents as is? bulder251 26 — 3y
0
You would need to move the VIPGui out of StarterGui. I recommend you put it in ServerStorage, then you need to change the GuiPath, that is in the script to the path of the GUI. NotedAPI 810 — 3y
View all comments (17 more)
0
Ok, I will kindly alert you what happens and if it works, if that is fine with you? Thanks again! bulder251 26 — 3y
0
Yep, that is fine! :D NotedAPI 810 — 3y
0
So when I say: local GuiPath = PATH it marks it as red, what would I put there? :D Thanks soo much for your help btw. bulder251 26 — 3y
0
Change "PATH" to the path as the GUI. For example, local GuiPath = game.ServerStorage:WaitForChild("VIPGui") NotedAPI 810 — 3y
0
Alrighty thanks! Sorry for the trouble let me test it out and get back to you! bulder251 26 — 3y
0
My main goal i for the exploiters to not be able to access the Gui at all if they do not own the game pass. So, I know the exploiters can access the properties and explorer with this certain exploit. Therefore, I want the Gui to delete entirely if the player does not own the game pass. This game is only for 1 player. bulder251 26 — 3y
0
I want the gui to delete if a player does not own the pass, so is there any way we can do that? bulder251 26 — 3y
0
Exploiters can't access ServerStorage NotedAPI 810 — 3y
0
Where is the ServerStorage? I only see ReplicatedStorage and ReplicatedFirst? bulder251 26 — 3y
0
Do you mean by ServerStorage, ReplicatedStorage? bulder251 26 — 3y
0
ServerStorage is below ServerScriptService I'm pretty sure. NotedAPI 810 — 3y
0
OK got it, let me try this out, thank you for baring with me, you could make a great tutor! bulder251 26 — 3y
0
Ok so, I have a problem I can no longer access this Gui even though I own the game pass. When I click the button it does not take me to it anymore? bulder251 26 — 3y
0
If I was to keep it how it is and not focus on this problem, do you personally think my game will be safe? bulder251 26 — 3y
0
What do you mean you click the button it does not take you to it anymore? Also, did you edit the PassID variable at the top to match the correct game pass ID? NotedAPI 810 — 3y
0
Yes, I did everything, but I have a text button in a different gui that when clicked it what have made the VIPGui frame visible, if that makes sense! :) bulder251 26 — 3y
0
Ah, you can just make a button inside the VIPGui and script that button to make the Frame or whatever show. NotedAPI 810 — 3y
Ad

Answer this question