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

script not cloning from a set table of numbers?

ok so if you read the script its pretty basic but im not sure if im using the list correctly because it will work for all the players on the list except the last 2 , not really sure if i should be using a table with {} or just keep as is but im also not sure on using a table with curly brackets

script:

local list = 38270341 or 291995028 or 131541716 or 41163273 or 303629801 or 759699976
game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function(char)
		if player.UserId == list then
			local gui = game.ServerStorage.DevTools:Clone()
			gui.Parent = player.PlayerGui
			print("gave "..player.Name.." DevTools")
		end
	end)
end)

1 comment

1

Because that is not how you define a table. What you are defining is a condition that finally evaluates to 38270341 Tables are defined by enclosing its values in {} and using a comma as a statement separator

1 answer

✓ Accepted answer

I never used this method, and maybe its limited somehow i'm not sure, that maybe why the last 2 arent working. But I guess the only thing that you have to do is use tables.

local list = {38270341, 291995028, 131541716, 41163273, 303629801, 759699976}

game.Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(char)
		for i = 1, #list do
        		if player.UserId == list[i] then
          		 local gui = game.ServerStorage.DevTools:Clone()
           		 gui.Parent = player.PlayerGui
           		 print("gave "..player.Name.." DevTools")
       			end
		end
    end)
end)

And in case you don't know much about tables lemme explain, So pretty much we assigned the table list and we put in it a couple of values, in our case those values are a number value (cuz IDs are numbers), a table is pretty much a variable that can store multiple values, and such as variables tables can have different types of values (integer, string, boolean, number.....)

So now, we have our values in our table; but how are we going to get them? for this you gotta do either do this

print(list[1]) -- pretty much its gonna print the 1st value in our table which is 38270341
print(list[2]) -- print 2nd value which is 291995028

-- and do that for all values

But this will just be boring and super inefficient, that's why we gotta use a generic for loop

local list = {38270341, 291995028, 131541716, 41163273, 303629801, 759699976}

for i, v in pairs (list) do
	print(v) 
	--[[ v stands for value, its the value that is going to pass through each time table loops 			 
   	around, so it will print all of them (in order ofc) without doing that stupid thing we did 	 
        earlier. i stands for index if you're wondering but its not rlly used that much but im happy 
        to explain]]
end

you can do it with this, but on the 1st script i looped the table around using a for loop, sometimes i prefer doing that for having a condition, which is checking if the ids are similar and its pretty much doing what a for loop gotta do but when we do list[i] pretty much the i variable will go up by 1 so each time it loops it will do (list[1], list[2], [list[3]..) so as you can see its all related but the ways change in terms of efficency, and if youre wondering what #list, # is an operator, so #list refers to the numbet of values list has, which is 6 (so like that i will go from 1 to 6)

I hope I helped! and if this didn't work, well im always here ¯\(?)/¯

3 comments

0

Thank you very much that actually gave me a better understanding of how to use tables

0

np

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