Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can you reference this with math.random?

Asked by 6 years ago

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

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

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
0
Yeah in the output it told me it was a number but i didnt know how to fix it. Thanks so much! MusicalDisplay 173 — 6y
Ad

Answer this question