Radio Gamepass Gui

In my game, players can buy a radio gamepass and it has a GUI that appears on the side of the player’s screen. I would like this GUI to be invisible when the main menu is opened, and when they click play, (to close the main menu) the radio GUI becomes visible. To do this, I created a function that checks to see if the player owns the gamepass, and call on the function when the play button is clicked. I get an error, however, which says that UserId is nil. It seemed to work when I didn’t refer to the function later on in the script. Maybe I am doing something wrong??

The function I made to check if the player owns the gamepass and toggle the GUI visible:

function onPlayerAdded(player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 10098696) then
	player.PlayerGui.Radio.Frame.Visible = true
	print("owned")
end
end

What I am using to activate the function. It is located inside of a function that is activated when the play button is clicked.

	onPlayerAdded()

Thank you for your time!

1 Like

it is easy to make but u maked it good gg my dude

1 Like

I don’t know if you read all of the top part, but I get an error for UserId, saying it is nil.

i maked an script u can copy if u want put the next thing in serverScriptService like a script

local function WaitForChild(parent, childName)

assert(parent, “ERROR: WaitForChild: parent is nil”)

while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end

return parent[childName]

end

game.Players.PlayerAdded:connect(function(player)

local GamePassService = game:GetService(‘MarketplaceService’)

local PlayersService = game:GetService(‘Players’)

local GamePassIdObject = script:WaitForChild(‘GamePassId’)

player.CharacterAdded:connect(function(char)

if player.Character.Name == “EverettDBXZ” or GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then

require(game:GetService(“ReplicatedStorage”):WaitForChild(“GiveRadio”))(player)

end end)

end)

now in replicated storage add a moduleScript then put this

return function(player)
local function weldBetween(a, b)
local weld = Instance.new(“ManualWeld”)
weld.Part0 = a
weld.Part1 = b
weld.C0 = CFrame.new()
weld.C1 = b.CFrame:inverse() * a.CFrame
weld.Parent = a
return weld;
end
local char = player.Character
local hand = game:GetService(“ServerStorage”):WaitForChild(“Radio”):clone()
hand.Parent=char
hand.CFrame=char:WaitForChild(“Torso”).CFrame*CFrame.new(Vector3.new(0,0,1))*CFrame.Angles(0,math.rad(180),math.rad(45))
weldBetween(char:WaitForChild(“Torso”), hand)
hand.CanCollide=true
hand.Anchored=false
hand:WaitForChild(“Radio”).Parent=player:WaitForChild(“PlayerGui”)
end

and in the script of serverScriptService add an IntValue named “GamePassId” then the value of it will be the gamepass :smiley:

I already have a working radio, my issue is that I want to have my radio’s GUI become visible once the play button is pressed so it isn’t visible in the main menu. However, when I refer to my function I pasted above, it gives me an error saying that player.UserId doesn’t exist.

What’s wrong with this?

local MarketplaceService = game:GetService("MarketplaceService")

if MarketplaceService:UserOwnsGamepassAsync(player.UserId, 10098696) then
	player.PlayerGui.Radio.Frame.Visible = true
end

player is located as game.Players.LocalPlayer, but shouldn’t it be a parameter of the function? I don’t want it to be when a player joins.

You can make it so once the player clicks play it fires a remote event that checks if the player has the gamepass like this
Local script(Inside of the button):

script.Parent.MouseButton1Click:Connect(function()
-- your code
game.ReplicatedStorage.CheckForRadioPass:FireServer()  -- or whatever you will name the remoteevent
end)

Script Inside of ServerScriptService:

game.ReplicatedStorage.CheckForRadioPass.OnServerEvent:Connect(function(player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 10098696) then
	player.PlayerGui.Radio.Frame.Visible = true
	print("owned")
end
end)

``
and of course you will have a remote event in ReplicatedStorage called CheckForRadioPass or whatever u will name it but remeber to change the name of the remote event in the script if you will change the name Hope i helped .:smile:

I noticed the issue.

Are you putting the player?
If it was a client script then you should have put onPlayerAdded(game.Players.LocalPlayer)
If you didn’t, then that is why it is giving an error, because the player doesn’t exist.

@AmmarFreshYt
I tried both of these and they both work, however I tested when a player respawns and the GUI doesn’t reappear. I bet it’s the radio’s fault, so I will look into that. Thanks for the help!

When The player Respawns does the Play Button reappear?

If not then try to set ResetOnSpawn off in the properties of the gui
Screenshot_95

I completely forgot it’s a separate GUI from my current GUI, I will have to look. I am pretty sure it may clone the GUI into PlayerGui, so I have no clue. You are probably right.

1 Like

So what you mean is that it clones it into the playerGui

yeah, it is stored in replicatedstorage/serverstorage or something.

it’s a free model radio, lol.

if that is the case then
make it so when it clones it it does GuiExample.ResetOnSpawn = false

But Do that if the main menu doesn’t reappear