Making this simple script work

I am making a system that kicks a player if they own a certain asset. I made a post yesterday and got smart people to help me get it working. Now ive ran into another problem. I cant add more then 1 asset ID. Heres my code:

local AssetId = 5972800229, 31117267
	
	game.Players.PlayerAdded:Connect(function(player)
	if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,AssetId) then
		player:Kick("I told you")
	end

end)

it doesnt work unless there is only one ID

1 Like
local AssetIds = {5972800229, 31117267}
	
game.Players.PlayerAdded:Connect(function(player)
	for i,v in pairs(AssetIds) do
		if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,v) then
			player:Kick("I told you")
		end
	end
end)

You need to use a table :wink:

local assets = {
	5972800229, 
    31117267
}
game.Players.PlayerAdded:Connect(function(player)
	for i = 1, #assets, 1 do
		if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, assets[i]) then
			player:Kick("you own a bad asset or somethign")
		end
	end
end)

I tried using a table and it didnt work. I must have did it wrong

that wont even work, youre just checking if they own the asset id “1” and “2” with this for loop. to do it this way you would have to use assets[i], not just i.

im stupid, i forgot to add [i], my bad

did my script work? unless i made a stupid mistake it should

It did work, Sorry about my stupidity

Thank you for the reply! This does work, I just like @TestAccount563344`s method more just because I understand it

1 Like

thanks, and I totally understand :slight_smile:

FYI the reason your original one didn’t work is because you have to run an individual check for each asset in the table; you can’t pass the table to PlayerOwnsAsset.

That actually makes sense. Thanks for the reply

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.