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

Help Me On This Block Extractor???

Asked by 10 years ago

I Want Rock To Pass But The Coal To Get Teleported Some Place Else I Made The Script But, It Won't Work Any Help?

positions = {[1] = -32.012, 2.03, -48.3,
             [2] = -33.302, 2.03, -48.3,
             [3] = -34.352, 2.03, -48.3,
             [4] = -35.412, 2.03, -48.3,
             [5] = -36.472, 2.03, -48.3}

function onTouched(hit)
    if hit.Name == "Coal" then
    hit.Position = (positions[math.random(1, #positions)])
    elseif hit.Name == "CleanedCoal" then
    hit.Position = (positions[math.random(1, #positions)])
    elseif hit.Name == "CleanedPolishedCoal" then
    hit.Position = (positions[math.random(1, #positions)])
    end
end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
10 years ago

Tables on ROBLOX are weird. The way to have another array/table inside of a table is to do this:

positions = {{-32.012, 2.03, -48.3},
             {-33.302, 2.03, -48.3},
             {-34.352, 2.03, -48.3},
             {-35.412, 2.03, -48.3},
             {-36.472, 2.03, -48.3}}

function onTouched(hit)
    pos = positions[math.random(1,#positions)] -- Even if it isn't the right block, just makes a value so you don't have to do it for each if-then pair
    if hit.Name == "Coal" then
    hit.Position = Vector3.new(pos[1],pos[2],pos[3]) -- Access the different positions inside the extracted table
    elseif hit.Name == "CleanedCoal" then
    hit.Position = Vector3.new(pos[1],pos[2],pos[3])
    elseif hit.Name == "CleanedPolishedCoal" then
    hit.Position = Vector3.new(pos[1],pos[2],pos[3])
    end
end

script.Parent.Touched:connect(onTouched)

Ad

Answer this question