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

If user owns gamepass make frame visible?

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

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!

2 comments

0

ServerScriptService.ClearSongs:4: attempt to index nil with 'WaitForChild' - it's giving me this issue now

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.

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