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

How can you reference this with math.random?

I'm making a Spleef game, and obviously I'm trying to get a hold of a RANDOM part each second so I can make it "disappear". The problems are: I'm pretty sure when you make a math.random object a local variable, It keeps that part and doesn't reference any other part BUT I have named all of the parts the same name, so I don't know if that will change anything.

while true do
	local part =  math.random(1, #SpleefParts:GetChildren())
	part.Transparency = 1
	part.CanCollide = false
	wait(1)
end

Pretty straightforward. Anybody?

1 answer

✓ Accepted answer

On your script, the variable part will just be a number, so this is how to pick a random instance.

while true do
	local part = SpleefParts:GetChildren()[math.random(1, #SpleefParts:GetChildren())]
	part.Transparency = 1
	part.CanCollide = false
	wait(1)
end

1 comment

0

Yeah in the output it told me it was a number but i didnt know how to fix it. Thanks so much!

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