Adding Premium Benefits into my game

Hello, I’m looking to add Premium Benefits into my game, for example: when a Premium member joins they automatically get a chat tag, I’m not sure if it would work with this script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

if player.MembershipType == Enum.MembershipType.Premium then
	
	game.Players.PlayerAdded:Connect(function(player)
			local tags = {
				{
					TagText = "Premium",
					TagColor = Color3.fromRGB(255, 255, 0) 
				}
			}
			local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
			local speaker = nil
			while speaker == nil do
				speaker = ChatService:GetSpeaker(player.Name)
				if speaker ~= nil then break end
				wait(0.01)
			end
			speaker:SetExtraData("Tags",tags)
			speaker:SetExtraData("ChatColor",Color3.fromRGB(0, 0, 255))
		end
	end)
	
end

I’ve reutilized the same script I use for a chat tag gamepass and re-adapted it into a Premium Benefits one but I’m not sure if it would actually work as I don’t have Premium. Should I change something in the script?

Thanks in advance

Well if its exactly the same then the other code you wrote just a change to the membership type then it should work.

What I don’t get is why you are doing “game.Players.PlayerAdded” because there is no need for this if this is a local script because local scripts run when a user joins so I don’t think there is any need for this.

I inserted the script into a normal script and not a LocalScript, should I switch it to localscript and remove the game.Players.PlayerAdded:Connect(function(player) string?

It should work fine in a server script. My bad I just noticed you where referencing the local player which only works in local scripts not server scripts so I automatically thought it was a server script. You should remove the “local player = Players.LocalPlayer” because that could cause issues and just deal with the player value given to you when you use the player added event.

image

I think it should work fine. What you could do to check is do

if player.MembershipType ~= Enum.MembershipType.Premium then

just to check to see if someone does not have Premium then if the tag will appear and then just change it again to == for Premium only. I checked the docs and it seems like this code should work fine and as long as there are no errors I guessing it should work fine.

1 Like

Gives me this error when I try to run the script:

On line 23, you should have “end)” instead of a normal “end”, that should fix the error.

I have the end) at line 23 but it still shows up the same error

It seems like you have an extra end, it has seemed to happen because of the code lines being too far (blue line), they should be at the green line instead as shown on the picture

Here I think this should be fixed:

game.Players.PlayerAdded:Connect(function(player)
	if player.MembershipType == Enum.MembershipType.Premium then
		local tags = {
			{
				TagText = "Premium",
				TagColor = Color3.fromRGB(255, 255, 0) 
			}
		}
		local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
		local speaker = nil
		while speaker == nil do
			speaker = ChatService:GetSpeaker(player.Name)
			if speaker ~= nil then break end
			wait(0.01)
		end
		speaker:SetExtraData("Tags",tags)
		speaker:SetExtraData("ChatColor",Color3.fromRGB(0, 0, 255))
	end
end)

Thanks a lot man! It works now!

1 Like

That was a kind of messy script, I’ll try to keep your tip in mind