GUI won't show up even if Player is a Premium member

Hi!

So I’m trying to add a Premium benefit for players if they play my game. It’s just a simple speed boost that’s 4 times the default WalkSpeed. The sprint toggle is an ImageButton within a ScreenGUI. In my code, I check if the player owns Premium, then if they do, I make the button visible to them so they can use it.

Since I don’t have Premium, I added a Premium Purchase Modal in my game and “bought” it while I was testing. After I “bought” Premium, the button did not show up. I tried resetting my character, but no luck.

Here’s the code, located in a Script within the ServerScriptService:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	if player.MembershipType == Enum.MembershipType.Premium then
		game.StarterGui.premiumbenefits.walkspeed.Visible = true -- "premiumbenefits" is the name of the ScreenGUI, and "walkspeed" is the name of the ImageButton.
	end
end)

Thank you for reading - any ideas as to what might be causing the problem?

Edit: Grammar mistake, sorry 'bout that!

2 Likes

Game.StarterGui won’t change the players GUI.

Do player.PlayerGui instead.

1 Like

You can’t use StarterGui to edit what a player sees in the game. StarterGui is pretty much where the server stores GUI objects. Then, once a player joins the game, everything inside the StarterGui gets copied into Player.PlayerGui, which is how the player will see things. To edit the GUI on a player-to-player basis, make a LocalScript inside the GUI which can access Players.LocalPlayer, and then check their membershiptype. If premium, you can enable the GUI, and if not premium, you can destroy it.

3 Likes

You can still use a server script. All @HappyLemonzYT has to do is change game.StarterGui to player.PlayerGui.

Didn’t work :confused: 30 characters

you can put a localscript and the gui in the same GuiScreen and do script.Parent.walkspeed.Visible = true

If it’s not working, then do this: player:WaitForChild(“PlayerGui”)

If that doesn’t work you can just do it in a local script.

You should run the check if player owns premium once your done buying since what your code is doing is just checking if you own premium whenever your added, i dont really know what “Premium Purchase Model” is but you get my point.

Scroll down to Premium Purchase Modal

https://developer.roblox.com/en-us/articles/premium-payouts

Your code is wrong.

Corrected code:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	if player.MembershipType == Enum.MembershipType.Premium then
                local pg = player:WaitForChild("PlayerGui")
		pg.premiumbenefits.walkspeed.Visible = true -- "premiumbenefits" is the name of the ScreenGUI, and "walkspeed" is the name of the ImageButton.
	end
end)

You were only making the Gui In StarterGui Visible for all future players connecting, you needed to mention PlayerGui to only change it for that user in that server. This needs to be a server script placed in Workspace or ServerScript Service. Still haveing problems oddly? Head over to developer.roblox.com or CKStudio +

Thanks, but still didn’t work :confused:

I’m still trying everyone else’s solutions, so I’m not stumped just yet.

So I put a LocalScript into the Button and wrote the following code into it:

local Players = game:GetService("Players")

Players.LocalPlayer:Connect(function(player)
	if player.MembershipType == Enum.MembershipType.Premium then
		player:WaitForChild("PlayerGui").premiumbenefits.walkspeed.Visible = true
	end
end)

And it doesn’t work. So I moved the LocalScript into the ScreenGUI and it still didn’t work. Thanks for helping though!

LocalScript in the ScreenGUI with the following code:

local Players = game:GetService("Players")

Players.LocalPlayer:Connect(function(player)
	if player.MembershipType == Enum.MembershipType.Premium then
		script.Parent.walkspeed.Visible = true
	end
end)

Doesn’t work :confused:
Thanks for helping though!

What do you mean by this? Like doing the .Visible or a separate thing altogether, like :Destroy()?

Sorry, your use of words just confused me. :sweat_smile:

How exactly are you checking if it works? Just want to know

1 Like

Remove the Players.LocalPlayer:Connect() function (keep the code inside of it tho).

I would change it to something like this:

local player = game.Players.LocalPlayer

if player.MembershipType == Enum.MembershipType.Premium then
	script.Parent.walkspeed.Visible = true
end
1 Like

Players.LocalPlayer isn’t an event, that is why it doesn’t work.

3 Likes
  1. I make the sprint button invisible before I start the game.
  2. I test the game.
  3. Since I don’t have Premium, I added a Premium Purchase Modal in game.
  4. So I “buy” Premium with that.
  5. I reset my character.
  6. I check to see if the button pops up/becomes visible or not.
1 Like

Put in a PremiumPurchaseCompleted event then and when that is fired make the button visible.

Sorry I’m on mobile right now so it’s hard to know exactly everything.

1 Like

Did you mean Players? (30 characters)

1 Like