Number representation through Variables

I’m trying to make a script that randomly selects a platform, and when a button is pressed, it makes a player fall through it. Here’s the script I’ve been using so far:

local pVal = math.Random(1,6)
local lv1 = workspace.Level1

script.Parent.ClickDetector.MouseClick:Connect(function()
    lv1.pVal.CanCollide = false
    lv1.pVal.CanCollide = 0.5
end

I’m pretty sure that this script is working except for the click function: I don’t know how to represent the value of pVal as a part. Any way to get around this?

1 Like

Assuming lv1 is what contains all parts, you can do

local lv1 = workspace.Level1:GetChildren()
local pVal = math.random(1,#lv1)

script.Parent.ClickDetector.MouseClick:Connect(function()
     lv1[pVal].CanCollide = false 
     lv1[pVal].CanCollide = 0.5 
end)
1 Like