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

how can I make it that a script checks how many objects there are and acts off that?

So, I have a script that makes a string value every time someone dies in a round. Here is a snip of it:

x = 0

local this  = Instance.new("StringValue")
this.Name = ("dead" .. x + 1 )
this.Value = a.Name
this.Parent = game.ReplicatedFirst.dead

x = x + 1

Trust me, that script works. In another script, I have that it makes a picture of whoever dies when I run it:

game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead1.Value
game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead1.Value

However, now I am trying to make it so that the script sees how many values there are in the folder and acts off that. For example, if there were 2 values in the folder, it would only go up to two and do this script:

game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead1.Value
game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead1.Value
wait(2)
game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead2.Value
game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead2.Value

and if it's three values it would do this script:

game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead1.Value
game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead1.Value
wait(2)
game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead2.Value
game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead2.Value
wait(2)
game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead3.Value
game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead3.Value

I know I can do a = game.ReplicatedFirst.dead:GetChildren() and use #a for each chance, but that would take too long and it's too much, does anyone know any other ways? If you have questions please leave them below!

9 comments

0

What do you mean "take too long" or "too much"?

0

I can do it but I am sure there are easier ways

0

if you have so many children that it's taking a long time then you could store the values in a folder named values or something and take the children of that folder instead which shouldn't take that long

0

I do store them in a folder, its just I want to know how to find out how to make the script find out how many values there are in the folder

0

I'm not sure if there is any other way other than #folder:GetChildren() , what exactly is the issue with doing that?

0

Use a for loop if you want a explanation i can give one.

0

My bad for in pair() do is what i meant

0

please give a explanation, i dont usually use pair loops

0

For in pair() do

1 answer

So something like this local table = :GetChildren() for i,v in pairs(table) do game.Workspace.fallen.SurfaceGui.ImageLabel.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. game.ReplicatedFirst.dead.dead[i].Value game.Workspace.fallen.SurfaceGui.name.Text = game.ReplicatedFirst.dead.dead[i].Value end

i is the index or number so it would be 1 the first time 2 the second time 3 the third time and v would the object you might wanna edit such as a list of players, I suggest looking up for loops if you are still confused.

1 comment

0

can you use the lua button so I can see the script a bit better, sorry :(

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