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

If user owns gamepass make frame visible?

Asked by 3 years ago
Edited 3 years ago

Learning as I build my game. Don't really know the reason why this doesn't work. Can someone help me figure out the issue?

So basically I made it so when a player owns the gamepassId it makes "ClearSongs" visible. However it isn't making the frame visible. Why's that?

local plr = game.Players.LocalPlayer
local marketplace = game:GetService("MarketplaceService")
local gamepassId = 9016487
local ClearSong = game.StarterGui.MainGui.Shop.ShopOpener.ScrollingFrame.ClearSongs

game.Players.PlayerAdded:Connect(function(plr)
    if  marketplace:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
        print("User owns victory songs")
        ClearSong.Visible = true
    end
end)

1 answer

Log in to vote
0
Answered by
Gokhaii 58
3 years ago
Edited 3 years ago

You are making it so the frame is visible to the StarterGui but not the PlayerGui. At the start of the game, everything in 'StarterGui' is cloned into 'PlayerGui' which is stored inside of the player on spawn.

To fix this, you just need to simply change the local variable you made.

Your version:

local ClearSong = game.StarterGui.MainGui.Shop.ShopOpener.ScrollingFrame.ClearSongs

Corrected Version:

local ClearSong = plr:WaitForChild("PlayerGui").MainGui.Shop.ShopOpener.ScrollingFrame.ClearSongs

(The code went a bit over line, just imagine it was 1 line.)

I hope this helps!

0
ServerScriptService.ClearSongs:4: attempt to index nil with 'WaitForChild' - it's giving me this issue now ItsJZaid 45 — 3y
0
Alternatively, you can have a look at the answer on this post: https://scriptinghelpers.org/questions/106625/how-do-i-make-the-gui-visible-to-a-local-player-if-the-player-has-the-gamepass. Maybe that could do it. Gokhaii 58 — 3y
Ad

Answer this question