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)
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)