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

Why does my script give a BillboardGui no matter what? Should check UserId

I've made a script with a gamepass that gives the player a BillboardGui if it isn't me or one of my friend.

Why does it execute even if it is the UserId that I specified in "no"

	local player = game.Players:FindFirstChild(script.Parent.Name)
	local no = {62903419, 21995652}
	local service = game:GetService("MarketplaceService")
	local passid = 5622548
	local char = workspace:FindFirstChild(player.Name)
	local bill = game.ServerStorage:WaitForChild("BillboardGui")
	
	if service:UserOwnsGamePassAsync(player.UserId, passid) == true then
		for i,v in pairs(no) do 
			if v ~= player.UserId then
				local clonething = bill:Clone()
				clonething.Parent = char.Head
			end
		end
	end

1 comment

0

You made a game pass that show a billboard gui if its not you or your friend? Wouldn't it have been easier just to write your names down and if it isn't you(Or anyone you specify.) then it shows the gui

1 answer

✓ Accepted answer

The reason it happens is because you're comparing the userids wrong. What you're doing is basically for each entry in the table "no", if the userid isn't the same as the entry, create the billboardgui. It means that for other players the gui gets created twice, because the condition at line 10 is matched twice. And for you & your friend it creates only one gui, because the condition is met once.

I suggest you to use a dictionary table instead, like so:

local player = game.Players:FindFirstChild(script.Parent.Name)
local no = {
	["62903419"] = true,
	["21995652"] = true
}
local service = game:GetService("MarketplaceService")
local passid = 5622548
local char = workspace:FindFirstChild(player.Name)
local bill = game.ServerStorage:WaitForChild("BillboardGui")

if service:UserOwnsGamePassAsync(player.UserId, passid) == true then
	if not no[tostring(plr.UserId)] then
		local clonething = bill:Clone()
		clonething.Parent = char.Head
	end
end

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