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

How can I delete a ScreenGui by a script if a player does not own a certain game pass?

Asked by 4 years ago
Edited 4 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
nachsor 36
4 years ago

Hey bulder251,

I think i see the issue. I believe that your issue is coming from the fact that you are trying to delete the GUI from the StarterGui. When the player loads in the game, if my memory serves correct, a copy of the GUI is made in PlayerGui. I believe that your script should destroy it there instead of from StarterGui. Hope this helps! :D

0
So you are saying I go from the game to the PlayerGui?Alrighty thanks, I will do that now! :D bulder251 26 — 4y
0
Yes. Instead of doing "game.StarterGui.VIPGui:Destroy()" you would do something like this "game.Players.LocalPlayer.PlayerGui.VIPGui:Destroy()". nachsor 36 — 4y
0
Ok! :D nachsor 36 — 4y
0
It says UserID is not a valid member of Player bulder251 26 — 4y
View all comments (5 more)
0
local MS = game:GetService("MarketplaceService") local ID = 0 if MS:UserOwnsGamePassAsync(game.Players.LocalPlayer.UserID, ID) == false then game.Players.LocalPlayer.VIPGui:Destroy() end bulder251 26 — 4y
0
"game.Players.LocalPlayer.VIPGui:Destroy()" you forgot PlayerGui after local player. So like this. "game.Players.LocalPlayer.PlayerGui.VIPGui:Destroy()". Not sure why its giving you that issue but maybe this will fix it? nachsor 36 — 4y
0
Should it be a local script under the gui? bulder251 26 — 4y
0
Yes, local script nachsor 36 — 4y
0
So, has it fixed the issue? nachsor 36 — 4y
Ad

Answer this question